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.

Continue reading

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.

Continue reading

How to Merge Documents when Importing a File into MongoDB

When you use mongoimport to import files into MongoDB, you have the option of merging existing documents with the ones that you’re importing.

In this case, if an imported document has the same _id value as an existing one in the collection that you’re importing into, the existing document will be merged with the one being imported.

You can also specify another field (other than the _id field) to be the matching field if required.

Continue reading