Complete the code to insert a document and let MongoDB auto-generate the _id.
db.collection.insertOne({ name: "Alice", [1] })When inserting a document without specifying _id, MongoDB auto-generates it. So you should not include _id in the document to let it be auto-generated.
Complete the code to find a document by its auto-generated _id.
db.collection.findOne({ _id: [1] })MongoDB stores _id as an ObjectId type, so you must use ObjectId("...") to query by it.
Fix the error in the code to insert a document with a custom _id.
db.collection.insertOne({ [1]: 1001, name: "Bob" })The field for the unique identifier in MongoDB documents is _id (with an underscore). Using any other name will not set the document's _id.
Fill both blanks to create a document with a custom _id and insert it.
db.collection.insertOne({ [1]: [2], name: "Carol" })To set a custom _id, use the field name '_id' and assign it a value like 1002 (number or string). Here, 1002 as a number is used.
Fill all three blanks to query documents with auto-generated _id and project only the name field.
db.collection.find({ [1]: { $exists: true } }, { [2]: 1, [3]: 0 })This query finds documents where _id exists (which is always true), and projects only the name field by including it (1) and excluding _id (0) from the output.