Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The insertOne method adds a single document to the collection.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using insertOne with an array will cause an error.
Using find or deleteMany does not add documents.
✗ Incorrect
The insertMany method adds multiple documents in one operation.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting numbers inside quotes stores them as strings.
Using null will not set a price.
✗ Incorrect
The price should be a number, not a string, to store it correctly.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers without quotes for city causes errors.
Putting zip code in quotes stores it as a string.
✗ Incorrect
The city should be a string and zip a number to represent the address correctly.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around strings causes syntax errors.
Passing date without quotes to Date constructor causes errors.
✗ Incorrect
The title and status are strings, and the date is passed as a string to the Date constructor.