简体   繁体   English

从具有所有指定单词的字段中查找文档

[英]Find doc from field having all specified words

I've problem to find the good document search request do find all documents containing in their 'name' field all the specified values.我很难找到好的文档搜索请求,确实可以找到在其“名称”字段中包含所有指定值的所有文档。

I've this document:我有这份文件:

{
    "_id" : ObjectId("607c1caa4b2964d0185301ff"),
    "nb" : 1,
    "name" : "mini computer 24GB"
}

When I run the following find request...当我运行以下查找请求时...

db.getCollection('test').find({"$text":{$search:'computer dummy'}})

... the document is returned. ... 文件被退回。 An OR is done but I want a AND operation. OR 已完成,但我想要 AND 操作。 Should I use a list of $and?我应该使用 $and 列表吗?

Many thanks非常感谢

I've problem to find the good document search request do find all documents containing in their 'name' field all the specified values.我很难找到好的文档搜索请求确实找到在其“名称”字段中包含所有指定值的所有文档。

I've this document:我有这个文件:

{
    "_id" : ObjectId("607c1caa4b2964d0185301ff"),
    "nb" : 1,
    "name" : "mini computer 24GB"
}

When I run the following find request...当我运行以下查找请求时...

db.getCollection('test').find({"$text":{$search:'computer dummy'}})

... the document is returned. ...文件被退回。 An OR is done but I want a AND operation. OR 已完成,但我想要 AND 操作。 Should I use a list of $and?我应该使用 $and 的列表吗?

Many thanks非常感谢

Ok I found.好的,我找到了。 each word must be in quotes as this:每个单词都必须用引号引起来,如下所示:

db.getCollection('test').find({$text:{$search:"\"computer\"  \"24GB\""}})

Not really intuitive!不是很直观!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 mongo查找具有指定键的对象的字段 - mongo find all with field that is object having a specified key 如何从 MongoDB 文档中删除具有指定值的字段? - How to remove a field having a specified value from a MongoDB document? 获取在mongoDB中添加到给定字符串中的字段中存在所有单词的集合列表 - get list of collections having all words exists in field which added in given string in mongoDB 如何查找包含所有元素匹配所有指定查询条件的数组字段的文档 - How to find documents that contain an array field with all elements that matches all the specified query criteria 如何从嵌套数组中获取字段和值并查询它们以在 mongodb 中查找文档? - how can I get field and value from nested array and query them to find doc in mongodb? 指定字段值上的Mongo Ruby驱动程序#find() - Mongo Ruby Driver #find() on Specified field Values 查找字段中出现次数最多的词 Mongodb - Find the most occurrence words exist in a field Mongodb Mongo —批量查找和更新整个文档(一个字段除外) - Mongo — Bulk Find and update whole doc except for one field mongodb的find()是否返回指定投影中缺少字段的对象? - Does mongodb's find() return objects missing a field from the specified projection? 如何在 mongo db 中更新具有给定值的指定字段 - How to update a specified field having a given value in mongo db
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM