Docs Menu

The $search Aggregation Pipeline Stage

On this page

  • Definition
  • Fields
  • Behavior
  • Troubleshoot Errors
Important

Looking for $searchBeta? Use $search instead, the official aggregation stage for running search queries.

Atlas Search queries take the form of an aggregation pipeline stage. The $search stage performs a full-text search on the specified field or fields which must be covered by an Atlas Search index.

A $search pipeline stage has the following prototype form:

{
$search: {
"index": "<index-name>",
"<operator-name>": {
<operator-specification(s)>
},
"highlight": {highlighting-options}
}
}

The $search stage takes a document with the following fields:

Field
Type
Necessity
Description
highlight
document
Optional
Document that specifies the Highlighting options for displaying search terms in their original context.
index
string
Optional
Name of the Atlas Search index to use. If omitted, defaults to default.
<operator-name>
string
Required
Name of the operator to search with. You can provide a document that contains the operator-specific options as the value for this field.

$search must be the first stage of any pipeline it appears in. $search cannot be used in:

Tip
See also:

The following error is returned if you run $search queries when the Atlas Search mongot process isn't installed or running:

MongoError: Remote error from mongot :: caused by :: Error connecting to localhost:28000.

The mongot process is installed only when the first Atlas Search index is defined. If you don't have any Atlas Search index in your Atlas cluster, create at least one Atlas Search index to resolve this error.

Give Feedback
© 2021 MongoDB, Inc.

About

  • Careers
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.