The _id in MongoDB has a special meaning and is always present in every document. It is used as the primary key for the collection.
It doesn't have to be generated automatically. You can specify its value manually if you want.
> db.people.insert( { _id : "rado", var : 1} ) > db.people.find() { "_id" : "rado", "var" : 1 } > db.people.insert( { _id : "top", var : 2} ) > db.people.find() { "_id" : "rado", "var" : 1 } { "_id" : "top", "var" : 2 } > db.people.insert( { _id : "top", var : 2} ) E11000 duplicate key error index: students.people.$_id_ dup key: { : "top" } > db.people.find() { "_id" : "rado", "var" : 1 } { "_id" : "top", "var" : 2 }
No comments:
Post a Comment