Apolon Pachulia
Apolon Pachulia

Reputation: 60

in MongoDB, how to search in text and arrays

We have db like this:

{
tags : ["key1", "key2", "key3", "car", "etc.."],
question : "some text here "
},
{
tags : ["bla1", "bla2", "bla3", "etc.."],
question : "My car is here"
}

I need query, that will get both rows with keyword "car"

I tried:

db.some.find(
 '$or' : [ ["tags" : "car" ], [ "$text" : [ "$search" : "car" ] ] ]
);

"question" is text index

Upvotes: 1

Views: 51

Answers (1)

Alex Blex
Alex Blex

Reputation: 37038

Unless you need to use $text, you can use plain $regex:

db.some.find({ $or:[ {tags:"car"}, {question:/car/} ] })

Upvotes: 3

Related Questions