0
0
MongoDBquery~10 mins

Auto-generated _id behavior in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to insert a document and let MongoDB auto-generate the _id.

MongoDB
db.collection.insertOne({ name: "Alice", [1] })
Drag options to blanks, or click blank then click option'
A_id: 12345
Bname: "Bob"
Cage: 25
D_id: ObjectId()
Attempts:
3 left
💡 Hint
Common Mistakes
Including _id manually when you want it auto-generated.
Using a fixed _id value which may cause duplicate key errors.
2fill in blank
medium

Complete the code to find a document by its auto-generated _id.

MongoDB
db.collection.findOne({ _id: [1] })
Drag options to blanks, or click blank then click option'
A"507f1f77bcf86cd799439011"
BObjectId("507f1f77bcf86cd799439011")
C12345
D"Alice"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the _id string without ObjectId() wrapper.
Using a number or other type instead of ObjectId.
3fill in blank
hard

Fix the error in the code to insert a document with a custom _id.

MongoDB
db.collection.insertOne({ [1]: 1001, name: "Bob" })
Drag options to blanks, or click blank then click option'
A_id
Bid
CID
DobjectId
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' or 'ID' instead of '_id'.
Misspelling the field name.
4fill in blank
hard

Fill both blanks to create a document with a custom _id and insert it.

MongoDB
db.collection.insertOne({ [1]: [2], name: "Carol" })
Drag options to blanks, or click blank then click option'
A_id
B1002
Cid
D"1002"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' instead of '_id'.
Putting quotes around the number when a number is intended.
5fill in blank
hard

Fill all three blanks to query documents with auto-generated _id and project only the name field.

MongoDB
db.collection.find({ [1]: { $exists: true } }, { [2]: 1, [3]: 0 })
Drag options to blanks, or click blank then click option'
A_id
Bname
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong field names in query or projection.
Including and excluding the same field in projection incorrectly.