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 get data.
Using 'update' or 'delete' which change or remove data.
✗ Incorrect
The find() method retrieves all 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: 25 })
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'find' which only reads data.
Using 'deleteOne' or 'updateOne' which remove or change data.
✗ Incorrect
The insertOne() method adds a single new document to the collection.
3fill in blank
hardFix the error in the code to update a document's age.
MongoDB
db.collection.updateOne({ name: 'Alice' }, { [1]: { age: 26 } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '$get' which is not a valid update operator.
Using '$add' or '$remove' which do not update fields.
✗ Incorrect
The $set operator updates the value of a field in a document.
4fill in blank
hardFill both blanks to delete a document where age is 30.
MongoDB
db.collection.[1]([2]: 30)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'remove' which is deprecated.
Using 'name' instead of 'age' in the filter.
✗ Incorrect
The deleteOne() method removes one document matching the filter. The filter uses the field age with value 30.
5fill in blank
hardFill all three blanks to find documents where age is greater than 20.
MongoDB
db.collection.find({ [1]: { [2]: [3] } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '$lt' which means less than.
Using wrong field names or values.
✗ Incorrect
This query finds documents where the age field is greater than ($gt) 20.