0
0
MongoDBquery~10 mins

$or 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 the field 'status' is either 'A' or 'D'.

MongoDB
db.collection.find({ $or: [ { status: [1] }, { status: 'D' } ] })
Drag options to blanks, or click blank then click option'
A'C'
B'B'
C'A'
D'E'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $or without an array.
Using incorrect quotes or missing quotes around string values.
2fill in blank
medium

Complete the code to find documents where 'age' is less than 30 or 'score' is greater than 80.

MongoDB
db.collection.find({ $or: [ { age: { $lt: [1] } }, { score: { $gt: 80 } } ] })
Drag options to blanks, or click blank then click option'
A30
B25
C35
D40
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gt instead of $lt for age.
Using a wrong number for comparison.
3fill in blank
hard

Fix the error in the query to correctly find documents where 'type' is 'book' or 'author' is 'John'.

MongoDB
db.collection.find({ $or: [ { type: 'book' }, { author: [1] } ] })
Drag options to blanks, or click blank then click option'
AJohn
B[ 'John' ]
C{ 'John' }
D'John'
Attempts:
3 left
💡 Hint
Common Mistakes
Using an object instead of an array for $or.
Not quoting string values.
4fill in blank
hard

Fill both blanks to find documents where 'category' is 'fiction' or 'year' is greater than 2010.

MongoDB
db.collection.find({ $or: [ { category: [1] }, { year: { $[2]: 2010 } } ] })
Drag options to blanks, or click blank then click option'
A'fiction'
Blt
Cgt
D'non-fiction'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt instead of $gt for year.
Not quoting string values for category.
5fill in blank
hard

Fill all three blanks to find documents where 'status' is 'active', or 'score' is at least 90, or 'age' is less than 25.

MongoDB
db.collection.find({ $or: [ { status: [1] }, { score: { $[2]: [3] } }, { age: { $lt: 25 } } ] })
Drag options to blanks, or click blank then click option'
A'active'
Bgte
C90
D'inactive'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gt instead of $gte for score.
Not quoting string values for status.