0
0
MongoDBquery~10 mins

Query filter syntax in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to find documents where the field "age" is exactly 25.

MongoDB
db.collection.find({"age": [1] })
Drag options to blanks, or click blank then click option'
A25
B"age"
C{ $gt: 25 }
D[25]
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number, which makes it a string.
Using an array instead of a single value.
Using a comparison operator when exact match is needed.
2fill in blank
medium

Complete the code to find documents where "score" is greater than 80.

MongoDB
db.collection.find({"score": { [1]: 80 }})
Drag options to blanks, or click blank then click option'
A$lt
B$eq
C$gt
D$ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using "$lt" which means less than.
Using "$eq" which means equal to.
Using "$ne" which means not equal.
3fill in blank
hard

Fix the error in the query to find documents where "status" is not "active".

MongoDB
db.collection.find({"status": { [1]: "active" }})
Drag options to blanks, or click blank then click option'
A$ne
B$eq
C$gt
D$in
Attempts:
3 left
💡 Hint
Common Mistakes
Using "$eq" which matches only "active" status.
Using "$gt" which is for greater than comparisons.
Using "$in" which expects an array of values.
4fill in blank
hard

Fill both blanks to find documents where "age" is at least 18 and less than 30.

MongoDB
db.collection.find({"age": { [1]: 18, [2]: 30 }})
Drag options to blanks, or click blank then click option'
A$gte
B$lt
C$lte
D$ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using "$gt" instead of "$gte" excludes 18.
Using "$lte" includes 30 which is not wanted.
Using "$ne" which is unrelated.
5fill in blank
hard

Fill all three blanks to find documents where "score" is greater than 50, "status" is "active", and "age" is less than 40.

MongoDB
db.collection.find({"score": { [1]: 50 }, "status": [2], "age": { [3]: 40 }})
Drag options to blanks, or click blank then click option'
A$gt
B"active"
C$lt
D$ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using "$ne" instead of "$gt" or "$lt".
Not quoting the string "active".
Mixing up greater than and less than operators.