1. What happens if you insert a document without an _id?
- The insert fails
- _id is left null
- MongoDB auto-generates an ObjectId
- It stores the document in a trash collection
Show answer
Answer: MongoDB auto-generates an ObjectId
MongoDB always ensures a unique _id, generating an ObjectId when one isn't provided.
Lesson: Collections & the _id Field