we can use the insert()
When insert the document, the _id
is automatically create with unique value of ObjectId
. Each document have different _id
.
Cannot insert the same value of _id
to the collection.
_id
can be anything as long as unique. But if the document insert does not have _id, mongoDB will assign as ObjectId
Insert order:
db.inspections.insert([{ "_id": 1, "test": 1 },{ "_id": 1, "test": 2 }, { "_id": 3, "test": 3 }])
_id
, the second document (which test = 2) will not add. But when insert is ran, only 1 document is inserted instead of two.{ "ordered": false }
to the insert()
db.inspections.insert([{ "_id": 1, "test": 1 },{ "_id": 1, "test": 2 }, { "_id": 3, "test": 3 }],{ "ordered": false })
updateOne()
and updateMany()
db.<collection_name>.updateOne({query},{update_operator})
db.zips.updateOne({ "city": "HUDSON" }, { "$inc": { "pop": 10 }})