0
0
MongoDBquery~10 mins

Custom _id values 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 with a custom _id value.

MongoDB
db.collection.insertOne({ _id: [1], name: "Alice" })
Drag options to blanks, or click blank then click option'
A"user123"
Bnull
C12345
DObjectId()
Attempts:
3 left
💡 Hint
Common Mistakes
Using ObjectId() when a custom string is needed.
Setting _id to null which is not allowed.
2fill in blank
medium

Complete the code to find a document by its custom _id value.

MongoDB
db.collection.findOne({ _id: [1] })
Drag options to blanks, or click blank then click option'
A"user123"
B123
CObjectId("507f1f77bcf86cd799439011")
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using ObjectId() when the _id is a string.
Using a number when the _id is a string.
3fill in blank
hard

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

MongoDB
db.collection.insertOne({ _id: [1], name: "Bob" })
Drag options to blanks, or click blank then click option'
A"123"
B123
CObjectId()
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string "123" instead of number 123.
Using ObjectId() when a number is needed.
4fill in blank
hard

Fill both blanks to update a document's name using its custom _id.

MongoDB
db.collection.updateOne({ _id: [1] }, { $set: { name: [2] } })
Drag options to blanks, or click blank then click option'
A"user123"
B"Charlie"
C"user456"
D"Dave"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong _id value in the filter.
Not using quotes around the name string.
5fill in blank
hard

Fill all three blanks to insert a document with a custom _id, name, and age.

MongoDB
db.collection.insertOne({ _id: [1], name: [2], age: [3] })
Drag options to blanks, or click blank then click option'
A"user789"
B"Eve"
C30
D25
Attempts:
3 left
💡 Hint
Common Mistakes
Putting numbers in quotes.
Using wrong types for _id or name.