Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $or without an array.
Using incorrect quotes or missing quotes around string values.
✗ Incorrect
The $or operator requires an array of conditions. Here, we want documents where status is 'A' or 'D'. So the first condition must be { status: 'A' }.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gt instead of $lt for age.
Using a wrong number for comparison.
✗ Incorrect
The condition is age less than 30, so $lt must be 30.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using an object instead of an array for $or.
Not quoting string values.
✗ Incorrect
The $or operator requires an array of conditions, not an object. The value for author should be a string 'John'.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt instead of $gt for year.
Not quoting string values for category.
✗ Incorrect
The first condition checks if category equals 'fiction'. The second condition uses $gt (greater than) for year > 2010.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gt instead of $gte for score.
Not quoting string values for status.
✗ Incorrect
The first condition checks status 'active'. The second uses $gte (greater than or equal) with 90 for score. The third checks age less than 25.