0
0
MongoDBquery~10 mins

Why insert operations matter in MongoDB - Test Your Understanding

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.users.[1]({ name: "Alice", age: 30 })
Drag options to blanks, or click blank then click option'
AinsertOne
BfindOne
CdeleteOne
DupdateOne
Attempts:
3 left
💡 Hint
Common Mistakes
Using findOne instead of insertOne will only search, not add.
Using updateOne or deleteOne changes or removes documents, not insert.
2fill in blank
medium

Complete the code to insert multiple documents at once.

MongoDB
db.orders.[1]([{ item: "book", qty: 3 }, { item: "pen", qty: 10 }])
Drag options to blanks, or click blank then click option'
AinsertOne
BinsertMany
Cfind
DdeleteMany
Attempts:
3 left
💡 Hint
Common Mistakes
Using insertOne with an array will cause an error.
Using find or deleteMany does not add documents.
3fill in blank
hard

Fix the error in the insert operation to add a document correctly.

MongoDB
db.products.insertOne({ name: "Laptop", price: [1] })
Drag options to blanks, or click blank then click option'
Anull
B"1000"
Cprice
D1000
Attempts:
3 left
💡 Hint
Common Mistakes
Putting numbers inside quotes stores them as strings.
Using null will not set a price.
4fill in blank
hard

Fill both blanks to insert a document with a nested address field.

MongoDB
db.customers.insertOne({ name: "Bob", address: { city: [1], zip: [2] } })
Drag options to blanks, or click blank then click option'
A"Seattle"
B98101
C"New York"
D12345
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers without quotes for city causes errors.
Putting zip code in quotes stores it as a string.
5fill in blank
hard

Fill all three blanks to insert a document with a date and status.

MongoDB
db.tasks.insertOne({ title: [1], dueDate: new Date([2]), status: [3] })
Drag options to blanks, or click blank then click option'
A"Finish report"
B"2024-06-01"
C"pending"
D"completed"
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around strings causes syntax errors.
Passing date without quotes to Date constructor causes errors.