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.
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.
Post Details
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/mongodb/com...