Starting from version 2.4, MongoDB has been supporting text indexes to search inside the string content. Text Search makes use of stemming techniques to search for specified words in the string fields by dropping stemming stop words like a, an, the, etc. Currently, MongoDB supports around 15 languages.
Initially text Search was an experimental feature, but starting from version 2.6, the configuration is enabled by default. But for the previous version of MongoDB, text search should be enabled with below code
Consider below document under posts collection which consists of the post text and its tags
Let’s create a text index on post_text field so that we can search inside our posts' text
Now that we have created the text index on post_text field, let’s search for all the posts which have the word wisdomjobs in their text.
Above command returns below result documents having the word wisdomjobs in their post text
For older versions of MongoDB, use below command
Using Text Search highly improves the search efficiency when compared to normal search.
To delete an existing text index, first find the name of index using below query
After getting the name of the index from above query, run below command. Here, post_text_text is the name of the index.
MongoDB Related Interview Questions
|Python Interview Questions||C & Data Structures Interview Questions|
|Hadoop Interview Questions||Node.js Interview Questions|
|Scala Interview Questions||Socket Programming Interview Questions|
|HBase Interview Questions||Solaris Administrator Interview Questions|
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.