in
Definition
The in
operator performs a search for an array of BSON number
,
date
, boolean
, objectId
, uuid
, or string
values at the given
path and returns documents where the value of the field equals any value
in the specified array. If the 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 | 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
static mappings on the collection, you
can run the following queries against the collections.
Sample Index
The sample index definition specifies the following actions to support
in
operator queries against the indexed fields in the collection:
Automatically index all the dynamically indexable fields in the collection.
Statically index the
name
field as the token type and converts the text in the field to lowercase.
{ "mappings": { "index": "default", "dynamic": true, "fields": { "name": { "normalizer": "lowercase", "type": "token" } } } }
To learn how to create an Atlas Search index, see Create an Atlas Search Index.