Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ObjectId() when a custom string is needed.
Setting _id to null which is not allowed.
✗ Incorrect
The _id field can be set to a custom string like "user123" to uniquely identify the document.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ObjectId() when the _id is a string.
Using a number when the _id is a string.
✗ Incorrect
To find a document with a custom string _id, use the exact string value in quotes.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string "123" instead of number 123.
Using ObjectId() when a number is needed.
✗ Incorrect
The _id can be a number like 123 without quotes to be numeric.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong _id value in the filter.
Not using quotes around the name string.
✗ Incorrect
Use the current _id value to find the document and set the new name as a string.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting numbers in quotes.
Using wrong types for _id or name.
✗ Incorrect
Insert a document with a string _id, string name, and numeric age.