MongoDB Exercises

Fill in the blanks to test your knowledge.

1

Find all documents in a collection

db.users.({})

2

Find documents where age is greater than 18

db.users.find({ age: { : 18 } })
3

Insert a single document

db.users.({ name: "Alice", age: 30 })
4

Update a document using $set

db.users.updateOne(
{ name: "Alice" },
{ : { age: 31 } }
)
5

Delete a single matching document

db.users.({ name: "Bob" })
6

Use aggregate to group documents

db.orders.([
{ $group: { _id: "$status" } }
])
7

Sort query results by name ascending

db.users.find().({ name: 1 })
8

Limit the number of returned documents

db.users.find().(5)