0
0
MongoDBquery~10 mins

$and operator behavior 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 age is greater than 25 and status is "A" using $and.

MongoDB
db.collection.find({ $and: [ { age: { $gt: [1] } }, { status: "A" } ] })
Drag options to blanks, or click blank then click option'
A25
B30
C20
D15
Attempts:
3 left
💡 Hint
Common Mistakes
Using a value less than 25 will include unwanted documents.
Using a value greater than 25 will exclude some valid documents.
2fill in blank
medium

Complete the code to find documents where score is at least 80 and grade is "B" using $and.

MongoDB
db.collection.find({ $and: [ { score: { $gte: [1] } }, { grade: "B" } ] })
Drag options to blanks, or click blank then click option'
A75
B80
C85
D70
Attempts:
3 left
💡 Hint
Common Mistakes
Using a value less than 80 includes lower scores.
Using a value greater than 80 excludes scores exactly 80.
3fill in blank
hard

Fix the error in the query to correctly use $and to find documents where city is "NY" and age is less than 30.

MongoDB
db.collection.find({ $and: [ { city: "NY" }, { age: { $lt: [1] } } ] })
Drag options to blanks, or click blank then click option'
Aage
B"30"
C30
D25
Attempts:
3 left
💡 Hint
Common Mistakes
Putting 30 in quotes makes it a string, causing no matches.
Using a field name instead of a value causes syntax errors.
4fill in blank
hard

Fill both blanks to find documents where status is "A" and score is greater than 70 using $and.

MongoDB
db.collection.find({ $and: [ { status: [1] }, { score: { $gt: [2] } } ] })
Drag options to blanks, or click blank then click option'
A"A"
B70
C75
D"B"
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers with quotes or strings without quotes.
Mixing up the values for status and score.
5fill in blank
hard

Fill all three blanks to find documents where age is at least 18, city is "LA", and active is true using $and.

MongoDB
db.collection.find({ $and: [ { age: { $gte: [1] } }, { city: [2] }, { active: [3] } ] })
Drag options to blanks, or click blank then click option'
A18
B"LA"
Ctrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings for numbers or booleans.
Using false instead of true for active.