$text search with $or results in "No query solutions"
Asked Answered
S

2

8

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

$or: [
  {
   $text: {
    $search: searchValue,
    $caseSensitive: false,
    $diacriticSensitive: false
   }
  },
  {
    content: {$regex: re}
  } 
]
St answered 8/1, 2018 at 7:48 Comment(7)
To use a $text query in an $or expression, all clauses in the $or array must be indexed. Is it so in your Mongo?Christychristye
Yes it is, I am searching the same field. content is indexed as text with OrbiterCMSArticles._ensureIndex({title: "text", content: "text", subtitle: "text"});St
What happens when you remove the regex part or the $text part ?Christychristye
Does it work when you use it via OrbiterCMSArticles.rawCollection().find(query) ?Compose
If I remove either part of the or condition, it works.St
No, it does work either with rawCollection ("Error: No query solutions")St
I have exactly the same issue, but it turned out that the issue for me was that I was not waiting for the indexes to be built.Emprise
E
1

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

Eads answered 17/10, 2019 at 13:39 Comment(1)
As said in the comments, that was not that. The field I was searching was already indexed. But thanks for your answer.St
R
0

What worked for me was creating a non-text index on all the fields that you are doing the $regex search on. A simple ascending or descending index should do the trick!

Repentance answered 19/8, 2021 at 19:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.