$text command for OR conditions on phrases

Hi MongoDB community,
I am using the db.collection.find{‘$text’:{‘$search’:‘""works at company1" "Adam" "’}} on a collection to extract documents which either have the phrase “works at company1” or have they keyword “Adam” or both. After a lot of debugging, i found out that mongosb breaks the phrase “works at company1” into words based on spaces and searches for “works” “at” “company1” and also gets me documents where i have “works at company2” in the value. The concerned documet doesnt have the keyword “Adam” in it so i am sure that the phrase “works at company1” is being split. Is this an error on part of mongodb creator team or is this done intentionally?

Hey @Abdul_Mateen1,

Welcome to the MongoDB Community Forums! :leaves:

Based on what you described and from the provided query, it seems you’re using $text operator for self-managed deployments and not the text operator for MongoDB Atlas search. There’s a way for you to include phrases in your find query as included in the documentation: Phrases using text

Since you have posted in the MongoDB Atlas category of the foums, I’m also recommending you the search operator that you can use, so do check and see if you can use the phrase operator of MongoDB Atlas. This way, you should be able to search for the works at company1 phrase. You can also add multiple phrases together so you can make your search include Adam too. But keep in mind, you’ll have to use aggregation in order to use this operator.

I have tried to list down all possible options for you to explore. I hope this helps. If you have any further questions or require additional assistance, please provide sample documents along with your search definition(if any) and your expected output, along with letting us know whether you’re using MongoDB Atlas or running a self-hosted, on-prem deployment.

Regards,
Satyam

Hi Satyam,

I accidentally posted my question in the wrong forum but when i went to change the category, it was too late and i wasn’t allowed to edit the categories anymore.

This is a self-managed deployment. If you look at the reference page of $textPhrases documentation provided by mongoDB, it doesnt talk about the OR condition on Phrases i am discussing above. it doesn’t talk about what to do if to want to find two or more phrases with an OR condition between them. for example how to do an OR with : “Works at company1” , “IBM” . i think the documentation is either incomplete or mongodb hasn’t implemented this functionality yet for the $text search.