Get the App
SLTechnology News&Howtos  ›  Database  › 

[MongoDB Learning Notes 6] in-depth creation / insertion of MongoDB (insert)

Shulou Source: shulou.com Published: 2022-06-01 17:16:49 10月30日 Update

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

Tags: Methods documents singles parameters arrays results if notes notes learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Tech Info Apple vpn Shulou Information