Recall & Review
beginner
What does the
$in operator do in MongoDB?The
$in operator matches documents where the value of a field equals any value in a specified array. It helps find documents with fields matching one or more values from a set.Click to reveal answer
beginner
How would you find documents where the field
color is either 'red', 'blue', or 'green'?Use
{ color: { $in: ['red', 'blue', 'green'] } }. This query returns documents where the color field matches any of the listed colors.Click to reveal answer
intermediate
Can
$in be used to match multiple types of values, like numbers and strings?Yes.
$in can match any values in the array, including mixed types like numbers and strings, as long as the field value equals one of them.Click to reveal answer
intermediate
What happens if the array passed to
$in is empty?If the array is empty,
$in matches no documents because there are no values to compare against.Click to reveal answer
intermediate
How is
$in different from using multiple $or conditions?$in is a concise way to check if a field matches any value in a list, while $or requires separate conditions for each value. $in is simpler and often more efficient.Click to reveal answer
Which query finds documents where
status is 'active' or 'pending'?✗ Incorrect
$in matches if the field equals any value in the array. $eq expects a single value, $or is used differently, and $nin excludes values.What does
{ age: { $in: [] } } return?✗ Incorrect
An empty array with
$in matches no values, so no documents are returned.Can
$in match values of different types in the same query?✗ Incorrect
$in can match any values in the array, including mixed types like strings and numbers.Which operator is a simpler alternative to multiple
$or conditions checking one field?✗ Incorrect
$in checks if a field matches any value in a list, replacing multiple $or conditions on the same field.If you want to find documents where
tags include 'mongodb' or 'database', which query is correct?✗ Incorrect
$in matches if any value in the array is present in the field. $all requires all values to be present.Explain how the
$in operator works in MongoDB queries and give a simple example.Think about checking if a field's value is one of several options.
You got /3 concepts.
Describe the difference between using
$in and multiple $or conditions for matching a set of values.Consider how you would write queries for the same condition in two ways.
You got /3 concepts.