最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - MongoDB: $or a full-text search and an $in - Stack Overflow

programmeradmin1浏览0评论

The problem

Hi. I have what seems to me as a strange problem and I'm at a loss with it:

Let's take:

tags   = [ ObjectId('a'), ObjectId('b') ]
search = { $search: 'abc' }

Now the following query works fine:

db.entries.find({ $or: [ {$text:search} ] })

And this one too:

db.entries.find({ $or: [ {tags:{$in:tags}} ] })

But bine them:

db.entries.find({ $or: [ {$text:search}, {tags:{$in:tags}} ] })

And I get the following error:

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

Meta-data

  • 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 oute.

My question

Help? :(

The problem

Hi. I have what seems to me as a strange problem and I'm at a loss with it:

Let's take:

tags   = [ ObjectId('a'), ObjectId('b') ]
search = { $search: 'abc' }

Now the following query works fine:

db.entries.find({ $or: [ {$text:search} ] })

And this one too:

db.entries.find({ $or: [ {tags:{$in:tags}} ] })

But bine them:

db.entries.find({ $or: [ {$text:search}, {tags:{$in:tags}} ] })

And I get the following error:

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

Meta-data

  • 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 oute.

My question

Help? :(

Share Improve this question edited Sep 30, 2014 at 9:01 Avaq asked Sep 30, 2014 at 8:29 AvaqAvaq 3,0211 gold badge23 silver badges25 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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.

Note

Other non-TEXT clauses under OR have to be indexed as well

Apparently I'll have to add an index to tags.

发布评论

评论列表(0)

  1. 暂无评论