$in
The $in operator in Amazon DocumentDB is a logical query operator that allows you to find documents where the value of a field equals any of the values specified in an array.
Parameters
-
field: The field to check against the provided array. -
[value1, value2, ...]: An array of values to match against the specified field.
Dollar ($) in field names
See Dollar($) and dot(.) in field names for limitations regarding querying $ prefixed fields in $in in nested objects.
Example (MongoDB Shell)
The following example demonstrates how to use the $in operator to find documents where the color field is one of the values in the provided array.
Create sample documents
db.colors.insertMany([ { "_id": 1, "color": "red" }, { "_id": 2, "color": "green" }, { "_id": 3, "color": "blue" }, { "_id": 4, "color": "yellow" }, { "_id": 5, "color": "purple" } ])
Query example
db.colors.find({ "color": { "$in": ["red", "blue", "purple"] } })
Output
{ "_id": 1, "color": "red" },
{ "_id": 3, "color": "blue" },
{ "_id": 5, "color": "purple" }
Code examples
To view a code example for using the $in command, choose the tab for the language that you want to use: