- Reference >
- Operators >
- Aggregation Pipeline Operators >
- Text Search Aggregation Operators >
- $meta (aggregation)
$meta (aggregation)¶
On this page
Definition¶
-
$meta
¶ New in version 2.6.
Returns the metadata associated with a document in a pipeline operations, e.g.
"textScore"
when performing text search.A
$meta
expression has the following syntax:The
$meta
expression can specify the following keyword as the<metaDataKeyword>
:Keyword Description Sort Order "textScore"
Returns the score associated with the corresponding $text
query for each matching document. The text score signifies how well the document matched the stemmed term or terms. If not used in conjunction with a$text
query, returns a score of null.Descending
Behavior¶
The { $meta: "textScore" }
expression is the only expression that the $sort
stage accepts.
Although available for use everywhere expressions are accepted in the
pipeline, the { $meta: "textScore" }
expression is only meaningful
in a pipeline that includes a $match
stage with a
$text
query.
Examples¶
Consider an articles
collection with the following documents:
The following aggregation operation performs a text search and use the
$meta
operator to group by the text search score:
The operation returns the following results:
For more examples, see Text Search in the Aggregation Pipeline.