0
0
MongoDBquery~10 mins

Why querying is essential 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.find([1])
Drag options to blanks, or click blank then click option'
A{}
B[]
Cnull
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using an empty array instead of an empty object.
Using null which does not work as a query filter.
2fill in blank
medium

Complete the code to find documents where age is 25.

MongoDB
db.collection.find({ age: [1] })
Drag options to blanks, or click blank then click option'
Atrue
B"25"
C{ $eq: 25 }
D25
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around 25, which makes it a string.
Using a query operator without the correct syntax.
3fill in blank
hard

Fix the error in the query to find documents with name 'Alice'.

MongoDB
db.collection.find({ name: [1] })
Drag options to blanks, or click blank then click option'
AAlice
B"Alice"
C{ $eq: Alice }
D'Alice'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around string values.
Using single quotes which may cause errors in some environments.
4fill in blank
hard

Fill both blanks to find documents where age is greater than 30.

MongoDB
db.collection.find({ age: { [1]: [2] } })
Drag options to blanks, or click blank then click option'
A$gt
B30
C25
D$lt
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt instead of $gt.
Using a wrong number value.
5fill in blank
hard

Fill all three blanks to find documents where name starts with 'J' and age is less than 40.

MongoDB
db.collection.find({ name: { [1]: [2] }, age: { [3]: 40 } })
Drag options to blanks, or click blank then click option'
A$regex
B"^J"
C$lt
D$gt
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gt instead of $lt for age.
Not using regex correctly for name.