0
0
MongoDBquery~10 mins

Tables vs collections thinking in MongoDB - Interactive Practice

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 'users' collection.

MongoDB
db.users.[1]()
Drag options to blanks, or click blank then click option'
Afind
Bselect
CgetAll
Dquery
Attempts:
3 left
💡 Hint
Common Mistakes
Using SQL terms like 'select' instead of MongoDB methods.
Trying to use 'getAll' which is not a MongoDB method.
2fill in blank
medium

Complete the code to insert a new document into the 'products' collection.

MongoDB
db.products.[1]({ name: 'Book', price: 9.99 })
Drag options to blanks, or click blank then click option'
Acreate
Badd
CinsertOne
Dpush
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'add' which is not a MongoDB method.
Trying to use 'create' which is not the correct MongoDB method.
3fill in blank
hard

Fix the error in the code to update the price of a product named 'Pen' to 1.5.

MongoDB
db.products.updateOne({ name: 'Pen' }, { [1]: { price: 1.5 } })
Drag options to blanks, or click blank then click option'
Aupdate
B$set
Cset
D$update
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the dollar sign in the update operator.
Using 'update' instead of '$set'.
4fill in blank
hard

Fill both blanks to delete all documents where the 'status' is 'inactive' in the 'accounts' collection.

MongoDB
db.accounts.[1]([2]: 'inactive')
Drag options to blanks, or click blank then click option'
AdeleteMany
Bremove
Cstatus
Dstate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'remove' which is deprecated in newer MongoDB versions.
Using the wrong field name like 'state' instead of 'status'.
5fill in blank
hard

Fill all three blanks to find documents in 'orders' where 'quantity' is greater than 10 and sort by 'date' descending.

MongoDB
db.orders.find({ [1]: { [2]: 10 } }).sort({ [3]: -1 })
Drag options to blanks, or click blank then click option'
Aquantity
B$gt
Cdate
Damount
Attempts:
3 left
💡 Hint
Common Mistakes
Using '$gte' instead of '$gt' for strictly greater than.
Sorting by 'amount' instead of 'date'.