MongoDB:$ 或全文搜索和 $in [英] MongoDB: $or a full-text search and an $in
本文介绍了MongoDB:$ 或全文搜索和 $in的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨.我有一个在我看来很奇怪的问题,我对此不知所措:
Hi. I have what seems to me as a strange problem and I'm at a loss with it:
让我们来看看:
tags = [ ObjectId('a'), ObjectId('b') ]
search = { $search: 'abc' }
现在以下查询工作正常:
Now the following query works fine:
db.entries.find({ $or: [ {$text:search} ] })
还有这个:
db.entries.find({ $or: [ {tags:{$in:tags}} ] })
但将它们结合起来:
db.entries.find({ $or: [ {$text:search}, {tags:{$in:tags}} ] })
我收到以下错误:
Unable to execute query: error processing query: ns=db.entries
Tree:
$or
tags $in [ ObjectId('a'), ObjectId('b') ]
TEXT : query=abc, language=, tag=NULL
Sort: {}
Proj: {}
No query solutions
元数据
- 我使用的是 MongoDB 版本
2.6.4
. - 将任一条件与简单的
{_id:"c"}
表达式结合使用都很好. - 我确实正确设置了文本索引.
- 条件在
$or
数组中出现的顺序不会影响结果. - I'm using MongoDB version
2.6.4
. - Combining either of the conditions with a simple
{_id:"c"}
expression works fine. - I do have my text-indices set up properly.
- The order in which the conditions appear in the
$or
-array doesn't influence the outcome.
Meta-data
帮助?:(
推荐答案
在稍微不同的环境下运行查询产生了更明显的错误:
Running the query under a slightly different environment produced a much more clear error:
Runner error: BadValue error processing query: ns=webistor.entries limit=0 skip=0
Tree: $or
tags $in [ ObjectId('a') ObjectId('b') ]
TEXT : query=abc, language=, tag=NULL
Sort: {}
Proj: {}
planner returned error: Failed to produce a solution for TEXT under OR - other non-TEXT clauses under OR have to be indexed as well.
注意
OR 下的其他非 TEXT 子句也必须编入索引
Other non-TEXT clauses under OR have to be indexed as well
显然我必须为 tags
添加一个索引.
Apparently I'll have to add an index to tags
.
这篇关于MongoDB:$ 或全文搜索和 $in的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文