Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

5
Generating unique integer for each document
Post Body

Summary: Is there a recommended way of ensuring each document has a unique integer assigned to it?

Explanation: I've got an existing interface tailored to an existing MySQL DB (that I have no control over). I need to implement this interface for MongoDB (that I have complete control over). The PK for a table is INTEGER in MySQL and thus the interface for things like getEntryById take an integer.

I figure I'll just have MongoDB generate a unique integer for property userId (the name of the PK in the MySQL table) but then still use _id for the PK (of type ObjectId).

Is there a recommended way of generating unique numbers like that? Obviously I could do something like max(allUserIds) 1 but is there a better way? There must be.

Edit Re-formated for clarity and put my question up front before explaining.

Author
Account Strength
100%
Account Age
13 years
Verified Email
Yes
Verified Flair
No
Total Karma
331,660
Link Karma
4,700
Comment Karma
325,787
Profile updated: 2 days ago
Posts updated: 1 month ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago