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.

Was it helpful?

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
scroll top