Igor Benikov
Igor Benikov

Reputation: 897

mongodb full text search for multiple phrases

if this is possible to search multiple phrases in mongodb?

for ex:

db.words.insert({name:"john cooper"})
db.words.insert({name:"mike spelman"})

and i need to find "john cooper" and "mike spelman"

i can to create query with single phrase:

db.words.find({$text:{$search : "\"mike serpsky\" john cooper"}})

and get:

{ "_id" : ObjectId("55f01b2c827e16e12f6eeebf"), "name" : "mike serpsky" }

but i can't create next query:

db.words.find({$text:{$search : "\"mike serpsky\" \"john cooper\""}})

if exist something way to do this in single query?

Upvotes: 3

Views: 1683

Answers (1)

Igor Benikov
Igor Benikov

Reputation: 897

Ok. Full text search not really helpful in this case. Solution founded with regular expressions:

db.words.find({"name": {$in : [/john cooper/, /mike serpsky/]}})

or

db.words.find({"name": /john cooper|mike serpsky/})

both works fine.

Upvotes: 2

Related Questions