0
0
MongoDBquery~10 mins

Why advanced stages 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 find all documents in the collection.

MongoDB
db.collection.[1]()
Drag options to blanks, or click blank then click option'
Afind
Bupdate
Cinsert
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'insert' instead of 'find' will add data, not retrieve it.
Using 'update' or 'delete' changes or removes data, not fetches it.
2fill in blank
medium

Complete the code to filter documents where age is greater than 25.

MongoDB
db.collection.find({ age: { [1]: 25 } })
Drag options to blanks, or click blank then click option'
A$gt
B$lt
C$eq
D$ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using '$lt' will find ages less than 25, not greater.
Using '$eq' looks for exactly 25, not greater.
Using '$ne' finds ages not equal to 25.
3fill in blank
hard

Fix the error in the aggregation pipeline to group by 'category'.

MongoDB
db.collection.aggregate([{ $group: { _id: "$ [1]" } }])
Drag options to blanks, or click blank then click option'
ACategory
Bcategory
Ccat
Dcategories
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'categories' or 'Category' will not match the field.
Using 'cat' is not the correct field name.
4fill in blank
hard

Fill both blanks to project only the 'name' and 'score' fields in the output.

MongoDB
db.collection.find({}, { [1]: 1, [2]: 1 })
Drag options to blanks, or click blank then click option'
Aname
Bscore
Cage
Daddress
Attempts:
3 left
💡 Hint
Common Mistakes
Including fields like 'age' or 'address' will show unwanted data.
Leaving out fields will exclude them from the output.
5fill in blank
hard

Fill all three blanks to update the 'status' field to 'active' for documents where 'age' is less than 30.

MongoDB
db.collection.updateMany({ age: { [1]: 30 } }, { [2]: { [3]: "active" } })
Drag options to blanks, or click blank then click option'
A$lt
B$set
Cstatus
D$gt
Attempts:
3 left
💡 Hint
Common Mistakes
Using '$gt' will select ages greater than 30, which is wrong.
Using wrong update operators will cause errors or no changes.
Misspelling the field name 'status' will fail the update.