Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7738967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:24:12+00:00 2026-06-01T08:24:12+00:00

I want to generate IDs for use with CouchDB. I’d like the IDs to

  • 0

I want to generate IDs for use with CouchDB. I’d like the IDs to be lexographically ascending by time so that I can sort on id without maintaining a seperate timestamp field. I know that CouchDB will generate ids with this property, but I don’t want the performance hit of querying the database, I’d rather just run an algorithm on my servers. I’d go with an implementation of rfc 4112 except that the results aren’t lexographically ascending. Is there any good reason I shouldn’t just do:

(Date.now()) + 'x' + Math.round(Math.random() *1E18)

(I’m using nodejs). Are there any costs of using a non-standard uuid, or of relying on javascript’s built in random function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T08:24:13+00:00Added an answer on June 1, 2026 at 8:24 am

    You have some choices when it comes to uuids.

    The first choice is if you want the _id generated client side(node, browser, etc..), or by couch. It sounds like you want to generate your own uuid on the client side. That is fine. Just stick the result of your function into the _id field of the doc you save to couchdb. Couch will just use that.

    You could have couch create the id. Couchdb only generates a _id if you don’t choose one for yourself. Couchdb by default uses a ‘sequential’ uuid generation algorithm. You can change the algorithm to others via futon and config. There is a section called ‘uuids’ with a key of ‘algorithm’. You can see the source for these algorithms here:

    https://github.com/apache/couchdb/blob/master/src/couchdb/couch_uuids.erl

    With descriptions about them here:

    http://wiki.apache.org/couchdb/HttpGetUuids?highlight=%28utc%5C_random%29

    As you can see the utc_random function is very similiar to your suggestion. But if you wanted your own,If you were inclined you could add you algorithm on the serverside and recompile couch.

    The second part of your question is about the performance of choosing different algorithms. I am going to quote Dave Cottlehuber from a user list post:

    CouchDB will have best insert time when your doc ids are
    continually increasing, as this minimises rewrites to the b~tree. This
    will also help
    your view build time for the same reason, and also minimises wasted doc space,
    although that would also be recovered during compaction.

    So both your algorithm and the utc_random should be fine as they doc ids are continually increasing do to the seemingly helpful one direction of time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to generate unique and random numbers or IDs which I can use
I want to use SEQUENCE strategy for automatically generate ids, but i am breaking
I want to generate a list of unique IDs. Because some of the IDs
Is it possible to use css with controls that generate ClientID and not regular
I usually use the UUID class to generate unique IDs. This works fine if
I want to use the Spine.js client-side framework, and it generates UUIDs as IDs
Does ASP.NET expose the underlying function it uses to generate session IDs? I want
I have a stored procedure, that generates some columns dynamically. I want to use
I generate dynamic enums that represent integer IDs from my database in a C#
I'm looking for a hash function that I can use to give uniform unique

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.