Docs Menu

Docs HomeMongoDB Atlas

in

On this page

  • Definition
  • Syntax
  • Fields
  • Examples

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.

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>
}
}
}
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:

  • boost: multiply the result score by the given number.

  • constant: replace the result score with the given number.

  • function: replace the result score using the function expression.

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

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.

←  geoWithinknnBeta →
Share Feedback
© 2023 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2023 MongoDB, Inc.