Keep in mind! You can create only one Text Index per collection!But! You can create one Text Index for all your fields in a collection:If you try it – don’t forget to remove the previous index

db.posts.createIndex( { "$**": "text" } )

And now you can search in all fields, f.e.:

db.posts.find( { $text: { $search: "indexes-power" } } )

this query will search in both Title and Url fields.

Sensitivity

As a human, Text Index can be sensitive. Case sensitive. Or insensitive. So, there are two ways of sensitivity:

Case sensitivity. Your index can be sensitive to the case of a text. If it’s insensitive, it will perceive “monGoDb” as “mongodb”. Case insensitive – is a default option.

Diacritic sensitivity. It’s hard to explain in Latin, but in Russian, we have letters “Ъ” and “Ь”. It’s absolutely different letters, but as you may notice – they look pretty similar. And diacritic insensitivity means that they will be treated as the same letter. This is also a default option. (you can find more diacritic letters in Unicode spec)

Weights

By default, all your kinda text fields in a collection have the same “importance” for search. I can check it on my index:

It can be useful if you have few fields and you are sure that some of them are more important for a customer. F.e. in e-commerce solution for products you may have a higher weight for a title, lower for a description and even lower for comments (yes, you can also add embedded documents into your index).

More

Some more things to keep in mind while using the Text Indexes.

You don’t need to manually stem your words, it is done automatically by MongoDB;

With it, keep in mind that if you use Text Index – your index file size will grow very fast;

MongoDB supports different languages for search, it’s important because it doesn’t count stop words in the search (like a, and, the);

I would definitely consider using MongoDB Text Indexes in case of an early startup/MVP, when there is just no time to struggle with more comprehensive but also more complex solution from Elastic or Sphinx.

That is it for MongoDB indexes for now. It’s still a big topic to discuss, though, and if I will find an interest in it – I will be writing more about this NoSQL DB with its indexes.