New in version 2.6.
$metaprojection operator returns for each matching document the metadata (e.g.
"textScore") associated with the query.
$metaexpression has the following syntax:
$metaexpression can specify the following keyword as the
Keyword Description Sort Order
Returns the score associated with the corresponding
$textquery for each matching document. The text score signifies how well the document matched the search term or terms. If not used in conjunction with a
$textquery, returns a score of 0.
<projectedFieldName> cannot include a dot (
.) in the name.
If the specified
<projectedFieldName> already exists in the matching documents, in the result set, the existing fields will return with the
$meta values instead of with the stored values.
$meta expression specifies the inclusion of the field to the result set and does not specify the exclusion of the other fields.
$meta expression can be a part of a projection document that specifies exclusions of other fields or that specifies inclusions of other fields.
The metadata returns information on the processing of the
<query> operation. As such, the returned metadata, assigned to the
<projectedFieldName>, has no meaning inside a
<query> expression; i.e. specifying a condition on the
<projectedFieldName> as part of the
<query> is similar to specifying a condition on a non-existing field if no field exists in the documents with the
To include a
$meta expression in a
sort() expression, the same
$meta expression, including the
<projectedFieldName>, must appear in the projection document. The specified metadata determines the sort order. For example, the
"textScore" metadata sorts in descending order.
For additional examples, see Text Search with Additional Query and Sort Expressions.
For examples of
"textScore" projections and sorts, see