How to perform TextSearch in MongoDB?

Text Search uses stemming techniques to look for specified words in the string fields by dropping stemming stop words like a, an, the, etc. At present, MongoDB supports more than 15 languages. We can create a text index for any field that has the text context.

db.collection.createIndex({ textFieldName: “text”})

After creating an index to text field we can search by any text which matches the text field value.

db.collection.find({$text:{$search: “hello”}})

To delete the text index first find the text index name with getIndexes(). After getting the name use dropIndex() method with the text index name parameter.