How to Exclude a Term From the Text Search?
Exclusion of term means when you perform search operation and do not want to display the document that contains the specified term, so you can exclude the term by prefixing a search keyword with the minus sign(-).
Using minus sign(-) you can exclude all the documents that contain excluded term. For example, you want to display all the documents that contain the keyword “Car” but not the “Cycle” keyword so you can use the following query:
dn.collectionName.find({$text:{$search:"Car -Cycle"}})
MongoDB Text Search
MongoDB Text Search technique finds a piece of text or a specified word from the string fields. It enables users to search for specific words or phrases within text fields efficiently.
The text index and $text operator perform text search in MongoDB, providing a powerful way to search for textual data in MongoDB collections.
Contact Us