How do you implement mongoDB's version of identity field in SQL Server?
-
08-10-2019 - |
Question
I always use an int column that is set as identity field as a primary key in a table in MS SQL. What is the best way to do this on MongoDB? I know that I can use the oid, but I want to use a number that can easily be read and remembered.
Thank you.
Solution
This article by Chris Shiflett explains how to create auto-incrementing IDs.
It makes use of MongoDB's atomic findAndModify command to increment and return an integer every time you need a new ID.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow