Reputation: 89
I have monogo collection with column name server_name an dos_name like below.
i have added index on server_name
db.createIndex({"server_name":"text"})
I want to search the record in with server name "Apple Mac pro" and "Cisco USB Mini"
I have tried below query.
db.collection_name.find({"$text": {"$search": '"Apple Mac Pro" "Cisco UCS Mini"'}});
but it giving blank result.
I have tried different different approaches like and multiple text search but want work.
thank you for your help.
Upvotes: 2
Views: 51
Reputation: 22276
Specifically for what you're describing you should just use $in
with an exact match:
db.collection_name.find({ server_name: { $in: ['Apple Mac Pro', 'Cisco UCS Mini'] } });
Assuming you do really want a $text
search then you have to execute two separate calls, due to the $text
restrictions
A query can specify, at most, one $text expression.
If the $search string includes a phrase and individual terms, text search will only match the documents that include the phrase.
Essentially two phrases execute $and
logic between them, and because you can only execute a single $text
query you need to split it into 2 calls.
Upvotes: 2