MongoDB: $ or full-text search and $ in

Problem

Hey. I have something that seems like a strange problem to me, and am in difficulty with this:

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 too:

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

But combine 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 am using MongoDB version 2.6.4 .
  • Combining any of the conditions with a simple expression {_id:"c"} works fine.
  • I really have my text indexes set.
  • The order in which conditions appear in $or -array does not affect the result.

My question

Help?: (

+8
javascript search mongodb
source share
1 answer

Running the request in a slightly different environment caused a much more obvious 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 sentences not related to TEXT under OR should also be indexed.

Apparently I need to add an index to the tags .

+6
source share

All Articles