Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$text search with $or results in "No query solutions"

Tags:

mongodb

meteor

This server side query in Meteor returns "No query solutions"

$or: [
  {
   $text: {
    $search: searchValue,
    $caseSensitive: false,
    $diacriticSensitive: false
   }
  },
  {
    content: {$regex: re}
  } 
]
like image 700
MickaelFM Avatar asked Jan 08 '18 07:01

MickaelFM


1 Answers

You must to create text indexes to map each element you wanna search. Example:

db.collection.createIndex({ element1: "text",
                            element2:'text' })

"To use a $text query in an $or expression, all clauses in the $or array must be indexed."

Restrictions are defined at $text behavior

like image 67
Hiago de Castro Avatar answered Nov 06 '22 02:11

Hiago de Castro