$text Operator
$text operator in MongoDB is used to search the text index. This operator performs text search operations on the collection with a text index.
This operator tokenizes each search string with whitespace and treats most punctuations as delimiters except – and \”. After tokenizing the search string it performs a logical OR operation on the tokens. If you want to sort the resultant documents then use the $meta query operator.
Syntax:
The syntax to use $text operator in MongoDB is:
$text:
{
$search: <string>,
$language: <string>,
$caseSensitive: <boolean>,
$diacriticSensitive: <boolean>
}
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