in
On this page
Definition
The in
operator performs a search for an array of number
,
date
, boolean
, or objectId
values at the given path and
returns documents where the value of the field equals any value in the
specified array. If the specified field holds an array, then the in
operator selects the documents whose field holds an array that contains
at least one element that matches any value in the specified array.
Syntax
The in
operator has the following syntax:
{ $search: { "index": <index name>, // optional, defaults to "default" "in": { "path": "<field-to-search>", "score": <options>, "value": <single-or-array-of-values-to-search> } } }
Fields
Field | Type | Description | Necessity |
---|---|---|---|
path | string | Indexed field to search. You can also specify a wildcard
path to search. See path construction for more information. | Required |
score | object | Score to assign to matching search term results. Use one of the following options to modify the score:
| Optional |
value | Value or values to search. Value can be either a single value or
an array of values of only one of the supported BSON types and
can't be a mix of different types. | Required |
Examples
The following examples use the in
operator to query collections in
the sample_analytics.customers collection. If
you load the sample data on your Atlas cluster and create an Atlas Search index named default
that uses
dynamic mappings on the collection, you
can run the following queries against the collections.