Why is there an underscore before the MongoDb document id?

Why is there an underscore before the MongoDb document id?

Why not name it "id" instead of "_id"?

Is this part of the naming convention that I don't know about?

+4
source share
1 answer

You may notice that MongoDB has many functions (in the shell) and fields starting with an abbreviation to indicate that they are internal or special and not provided by the user.

If you have your own "identifier", you can save it as an "id" and still use the by-by-MongoDB _id field, although you do not need to use the ObjectId that MongoDB generates - you can save your own natural primary key in the "_id" field, which will always have a unique index.

+9
source

All Articles