【问题标题】:How to search text in specific documents and not all documents in mongodb?如何在特定文档中搜索文本而不是 mongodb 中的所有文档?
【发布时间】:2021-11-27 23:48:51
【问题描述】:

首先我为我的数据创建了索引:

db.stores.find( { $text: { $search: "java coffee shop" } } )

这是在索引字段中搜索文本的代码。

db.stores.find( { $text: { $search: "shop" } } )

但问题是它在我的集合中搜索“shop”这个词的整个文档,并且我想将它的探索限制在一些特定的文档中,例如它们的 id。 换句话说,我只想在我收藏的文档中搜索“shop”这个词 他们的 Occupation 字段的值等于“Z1”;

【问题讨论】:

    标签: mongodb


    【解决方案1】:

    您可以像这样添加其他字段:

    db.stores.find( { occupation: "Z1", $text: { $search: "shop" } } )

    【讨论】:

      猜你喜欢
      • 2017-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-25
      • 1970-01-01
      • 2023-02-14
      • 1970-01-01
      • 2016-10-13
      相关资源
      最近更新 更多