Exclude a Term From the Text Search Example
Let’s look at some examples of excluding a term from text search in MongoDB to understand the concept better.
In the following example, we are working with:
Database: gfg
Collection: content
Document: The content collection contains the three documents.
In this example, we only display those documents that contain dog not cow
Query:
db.content.find({$text:{$search:"dog -cow"}})
Output:
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.