Creating Documents

📌 insertOne()

Click the create collection button. Then click the insert document button.

_id is the unique id for every document in mongodb

Using mongo shell:

db.COLLECTION_NAME.insertOne({title: "this is a title", year: 1900})

📌 insertMany()

Using mongo shell:

db.COLLECTION_NAME.insertMany([{_id: "123"},{_id:"124"}])

Insert many does an ordered insert by default, this means that as soon as this finds an error it will stop inserting documents.

To change the behavior of ordered insert, add after the array a document:

{"ordered": false}

Last updated