Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find all documents in the collection.
MongoDB
db.collection.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using insert() instead of find() to retrieve data.
Using update() or delete() which modify data instead of reading.
✗ Incorrect
The find() method retrieves documents from a MongoDB collection.
2fill in blank
mediumComplete the code to insert a new document into the collection.
MongoDB
db.collection.[1]({ name: 'Alice', age: 30 })
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using find() which only reads data.
Using updateOne() which changes existing data.
✗ Incorrect
The insertOne() method adds a single new document to the collection.
3fill in blank
hardFix the error in the query to update a document's age.
MongoDB
db.collection.updateOne({ name: 'Bob' }, { [1]: { age: 35 } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the '$' sign before set.
Using 'update' instead of '$set'.
✗ Incorrect
The $set operator updates specific fields in a document.
4fill in blank
hardFill both blanks to query documents where age is greater than 25.
MongoDB
db.collection.find({ age: { [1]: [2] } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt which means less than.
Using wrong comparison number.
✗ Incorrect
The $gt operator means 'greater than'. So this finds documents with age > 25.
5fill in blank
hardFill all three blanks to create a denormalized document with embedded address.
MongoDB
db.collection.insertOne({ name: 'Eve', age: 28, address: { [1]: '123 Main St', [2]: 'Springfield', [3]: 'IL' } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'zipcode' instead of 'state' for the third blank.
Not embedding address as a sub-document.
✗ Incorrect
In denormalization, related data like address is embedded. The keys are street, city, and state.