[MongoDB Learning Notes 6] in-depth creation / insertion of MongoDB (insert)
A simple insert method is used to insert a single document:
> db.post.insert ({"bar": "baz"}); WriteResult ({"nInserted": 1})
Batch insert, using the insert method (the parameter is an array of documents):
> db.post.insert ([{"_ id": 0}, {"_ id": 1}, {"_ id": 2}]) BulkWriteResult ({"writeErrors": [], "writeConcernErrors": [], "nInserted": 3, "nUpserted": 0, "nMatched": 0, "nModified": 0, "nRemoved": 0, "upserted": []}) >
View the results of the insertion:
> db.post.find (); {"_ id": ObjectId ("54a51cfd7f46906f81b7adcd"), "bar": "baz"} {"_ id": 0} {"_ id": 1} {"_ id": 2} >
Note: the batchInsert method is no longer available in the new version of mongoDB