Text search operator in MongoDB is used to perform text search queries on the content stored in the text indexes.
Steps to use text search operator in MongoDB:
1. Create a Text Index: MongoDB uses text indexes to perform text search. First, you need to create a text index on the field.
```
db.collection.createIndex( { field: “text” } )
```
1. Use Text Operator: Text search query uses the `$text` operator to search for words and phrases in the string content.
```
db.collection.find( { $text: { $search: “search_string” } } )
```
1. Use search string: The `$search` field is used to specify the search string. MongoDB matches the search string against the text index.
1. Use Boolean operators: Text search queries use Boolean operators (`OR`, `AND`, `NOT`) to refine the search results.
```
// OR Operator
db.collection.find( { $text: { $search: “word1 word2” } } ) // It will match any of the terms.
// AND Operator
db.collection.find( { $text: { $search: “\“word1 word2\”“ } } ) // It will match all the terms.
// NOT Operator
db.collection.find( { $text: { $search: “word1 -word2” } } ) // It will exclude documents that contain term “word2”.
```
1. Case Sensitivity: By default, text search is case insensitive. However, the `$caseSensitive` option can be used to perform case-sensitive text search.
```
db.collection.find( { $text: { $search: “word”, $caseSensitive: true } } )
```
1. Diacritic Sensitivity: By default, text search is diacritic sensitive. However, the `$diacriticSensitive` option can be used to perform diacritic-insensitive text search.
```
db.collection.find( { $text: { $search: “word”, $diacriticSensitive: true } } )
```
Note: You can only have one text index per MongoDB collection. If you need to index multiple fields, you have to do it all at once in the same index.