Create a Text Index with Different Field Weights in MongoDB

When you create a text index in MongoDB, you have the option of applying different weights to each indexed field.

These weights denote the relative significance of the indexed fields to each other. A field with a higher weight will have more impact in the search results than a field with a lower weight.

This provides you with a certain amount of control over how the search results are calculated.

The default weight is 1, so if you don’t specify a weight for field, it will be assigned a weight of 1.

Read more

Create a Wildcard Text Index in MongoDB

MongoDB provides us with the ability to create wildcard text indexes.

Wildcard text indexes are similar to wildcard indexes, except that wildcard text indexes support the $text operator, whereas wildcard indexes don’t.

That said, creating each index type is very similar in the sense that they both share the wildcard $** field pattern.

Read more

MongoDB dropIndexes()

In MongoDB, the dropIndexes() method allows you to drop one or more indexes from a collection.

To drop a single index, pass the name of the index or its definition/specification document. If it’s a text index, you can only specify the index name.

To drop multiple indexes, pass the index names in an array.

To drop all indexes (except for the _id index), don’t pass any arguments.

Read more

MongoDB dropIndex()

There are several ways to drop an index in MongoDB, one of which is to use the dropIndex() method.

It’s pretty simple to use – just pass the name of the index or its definition/specification document. If it’s a text index, you can only specify the index name.

Read more

How unhideIndex() Works in MongoDB

In MongoDB, the db.collection.unhideIndex() method unhides a hidden index.

A hidden index is one that’s hidden from the query planner. When you unhide an index, it is no longer hidden from the query planner, and it’s immediately available for use.

Read more

How hideIndex() Works in MongoDB

MongoDB introduced the db.collection.hideIndex() method in MongoDB 4.4.

This method hides an existing index from the query planner. This allows you to evaluate the potential impact of dropping an index without actually dropping the index.

If hiding it has a negative impact, you can use db.collection.unhideIndex() to unhide the index. This saves you from having to drop the index, then recreate it.

Read more