Docs Menu
Docs Home
/
Atlas
/ / /

Choose the Aggregation Pipeline Stage

Atlas Search queries run inside an aggregation pipeline stage, which is the preferred method for performing aggregations.

Aggregation operations process multiple documents and return computed results. You can use aggregation operations to:

  • Group values from multiple documents together.

  • Perform operations on the grouped data to return a single result.

  • Analyze data changes over time.

You can use either the $search or the $searchMeta stage as the first stage in the aggregation pipeline.

Aggregation Pipeline Stage
Description

Conducts full-text searches and returns an ordered list of documents along with additional search metadata. Use $search to retrieve matching documents with or without facets.

Conducts full-text searches and returns the metadata without fetching the documents. Use $searchMeta to retrieve only the metadata about your search results, such as the total count of matching documents or facets.

After the $search or the $searchMeta stage completes, you can use additional aggregation stages to process documents further. For example, you can use one or more of the following stages, in addition to other stages:

Aggregation Pipeline Stage
Description

Limits the number of documents passed to the next stage in the pipeline.

Skips documents that pass into the stage and passes the remaining documents to the next stage in the pipeline.

Passes along documents with the requested fields to the next stage in the pipeline.

Adds new fields to documents.

Processes multiple aggregation pipelines within a single stage on the same set of input documents.

Filters documents based on a specified query predicate and passes matched documents to the next pipeline stage.

Combines documents with the same fields or expression into a single document by a group key.

Performs a left outer join to a collection in the same database to filter in documents from the "joined" collection for processing.

When you add these stages to your aggregation pipeline, consider the potentially significant performance impact.

To improve performance, we recommend that you use $limit for search results, paginate through search results as needed, and retrieve search results after a reference point.

Back

Query Reference