Chapter 3 Insert error quiz

what is the answer for this question can anyone tell?
Select all true statements from the following list:

MongoDB can always store duplicate documents in the same collection regardless of the _id value.

MongoDB can store duplicate documents in the same collection, as long as their _id values are different.

There is no way to ensure that duplicate records are not stored in MongoDB.

If a document is inserted without a provided _id value, then that document will fail to be inserted and cause a write error.

If a document is inserted without a provided _id value, then the _id field and value will be automatically generated for the inserted document before insertion.

Hi @Melvin_Thomas,

Note that many statements apply. I’d first remember that the main field used to detect duplicates is _id (or unique indexed fields). _ids must always be different.

This makes for the first 2 answers:

  1. :negative_squared_cross_mark:
  2. :white_check_mark:

The third one is tricky, it means: _ MDB can’t avoid duplicates_, which is false if I understand correctly.

For the last 2, I recommend you to test in the database, using insertOne({}) method. Checking whether it is inserted or not and the shape of it will answer both.

Please, take into account that I may miss something, this was more an opinion and some hints.

PS: in the real world, you may use some other field like username or email, or a compound index, to ensure there are no duplicates :slight_smile:.


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.