Phrase Search in MongoDB
Instead of searching a single word you are also allowed to search for a phrase by wrapping the phrase in double quotes(“”). Generally, the phrase search performs OR operation in between the specified keywords.
For example, the phrase is “I like Mango”, then phase search looks for all the documents that contain keywords either I, like, or Mango. And if you want to perform an exact phrase search then wrap the phase in between escaped double quotes(\”).
MongoDB Phrase search Syntax:
db.collectionName.find({$text:{$search:”Phrase”}})
MongoDB Exact Phrase Search Syntax:
db.collectionName.find({$text:{$search:”\”Phrase”\”}})
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