参考 > 参考 > 经营者 > 聚合管道运营商 > $ meta(汇总)
在本页面
$meta
返回流水线操作中与文档关联的元数据,例如"textScore"在执行文本搜索时。
"textScore"
甲$meta表达的语法如下:
{ $meta: <metaDataKeyword> }
该$meta表达式可以将以下关键字指定为<metaDataKeyword>:
<metaDataKeyword>
$text
MongoDB Atlas Search提供了其他$meta关键字,例如:
有关详细信息,请参考Atlas Search文档。
该表达式是唯一的表达,该阶段接受。{ $meta: "textScore" }$sort
{ $meta: "textScore" }
$sort
尽管可以在管道中接受表达式的任何地方使用该表达式,但是该表达式仅在包含带有查询阶段 的管道中才有意义。{ $meta: "textScore" }$match$text
$match
视图不支持文本搜索。
考虑包含articles以下文档的集合:
articles
{ "_id" : 1, "title" : "cakes and ale" } { "_id" : 2, "title" : "more cakes" } { "_id" : 3, "title" : "bread" } { "_id" : 4, "title" : "some cakes" }
以下聚合操作执行文本搜索,并使用 $meta运算符对文本搜索分数进行分组:
db.articles.aggregate( [ { $match: { $text: { $search: "cake" } } }, { $group: { _id: { $meta: "textScore" }, count: { $sum: 1 } } } ] )
该操作返回以下结果:
{ "_id" : 0.75, "count" : 1 } { "_id" : 1, "count" : 2 }
有关更多示例,请参见“聚合管道”中的“文本搜索”。