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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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.