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.
✗ 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: 30 })
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using find() to add data instead of insertOne().
✗ 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: 'Alice' }, { [1]: { age: 31 } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $get or $add which are not valid update operators.
✗ Incorrect
The $set operator updates the value of a field in a document.
4fill in blank
hardFill both blanks to find 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 (less than) instead of $gt (greater than).
✗ Incorrect
The $gt operator means 'greater than'. We want ages greater than 25.
5fill in blank
hardFill all three blanks to delete documents where status is 'inactive' and age is less than 20.
MongoDB
db.collection.deleteMany({ status: [1], age: { [2]: [3] } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'active' instead of 'inactive' for status.
✗ Incorrect
We delete documents where status is 'inactive' and age is less than 20 using $lt.