0
0
MongoDBquery~10 mins

insertOne method 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 single document into the collection.

MongoDB
db.collection.[1]({ name: "Alice", age: 25 })
Drag options to blanks, or click blank then click option'
AinsertOne
BinsertMany
CfindOne
DupdateOne
Attempts:
3 left
💡 Hint
Common Mistakes
Using insertMany instead of insertOne for a single document.
Using findOne which only reads data.
Using updateOne which modifies existing data.
2fill in blank
medium

Complete the code to insert a document and handle the returned promise.

MongoDB
db.collection.insertOne({ item: "book", qty: 10 }).[1](result => console.log(result.insertedId))
Drag options to blanks, or click blank then click option'
Acatch
Bthen
Cawait
Dfinally
Attempts:
3 left
💡 Hint
Common Mistakes
Using catch instead of then for success handling.
Using await without async function.
Using finally which runs regardless of success or failure.
3fill in blank
hard

Fix the error in the code to correctly insert a document.

MongoDB
db.collection.insertOne({ name: "Bob", age: 30 [1] )
Drag options to blanks, or click blank then click option'
A}
B]
C)
D;
Attempts:
3 left
💡 Hint
Common Mistakes
Closing the object with a square bracket instead of curly brace.
Missing the closing brace causes syntax errors.
Adding a semicolon inside the method call.
4fill in blank
hard

Fill both blanks to insert a document and print the inserted ID.

MongoDB
db.collection.[1]({ name: "Eve", active: true }).[2](res => console.log(res.insertedId))
Drag options to blanks, or click blank then click option'
AinsertOne
BinsertMany
Cthen
Dcatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using insertMany for a single document.
Using catch instead of then for success handling.
5fill in blank
hard

Fill all three blanks to insert a document, handle success, and catch errors.

MongoDB
db.collection.[1]({ username: "john_doe" }).[2](res => console.log(res.insertedId)).[3](err => console.error(err))
Drag options to blanks, or click blank then click option'
AinsertOne
Bthen
Ccatch
DinsertMany
Attempts:
3 left
💡 Hint
Common Mistakes
Using insertMany instead of insertOne.
Mixing up then and catch methods.