Chapter 3: Creating and Manipulating Documents - Quiz: Insert Order

In the lecture: MongoDB m001 Inserting New Documents insert order v5 - YouTube

says that all the documents with unique _id will be inserted and all the documents that have duplicate _id values will produce their own error and not will be inserted.

but in the quiz the option which is the almost the same of lecture says that will be inserted 3 new documents…
db.pets.insert([{ “_id”: 1, “pet”: “cat” },
{ “_id”: 1, “pet”: “dog” },
{ “_id”: 3, “pet”: “fish” },
{ “_id”: 4, “pet”: “snake” }], { “ordered”: false })

someone can explain me better?

The collection is empty at the beginning. So the _id:1 gets inserted because there is no other document, there is not duplicate, in the the collection.

The second _id:1 is not inserted because once the first _id:1 is inserted all other _id:1 are duplicate of an existing _id.

3 Likes