Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to reindex MongoDB Collection after some period of time like RDBMS

Tags:

mongodb

I like to get some knowledge on reindexing the MongoDB. Please forgive me as I am asking some subjective questions.

The questinon is : Do MongoDB needs to do reindexing periodically like we do for RDBMS or Mongo automatically manages it.

Thanks for your fedback

like image 424
Arpan Avatar asked Feb 27 '14 05:02

Arpan


People also ask

Do we need to rebuild index in MongoDB?

According to MongoDB documentation: Normally, MongoDB compacts indexes during routine updates. For most users, the reIndex command is unnecessary. However, it may be worth running if the collection size has changed significantly or if the indexes are consuming a disproportionate amount of disk space.

Why do we need indexing in MongoDB?

Indexes support the efficient execution of queries in MongoDB. Without indexes, MongoDB must perform a collection scan, i.e. scan every document in a collection, to select those documents that match the query statement.

Are MongoDB indexes strongly consistent?

Learn more about MongoDB transactions here. Supported indexing strategies such as compound, unique, array, partial, TTL, geospatial, sparse, hash, wildcard and text ensure optimal performance for multiple query patterns, data types, and application requirements. Indexes are strongly consistent with the underlying data.

How many indexes does MongoDB create by default for a new collection?

MongoDB provides two geospatial indexes known as 2d indexes and 2d sphere indexes using these indexes we can query geospatial data.


1 Answers

Mongodb takes care of indexes during routine updates. This operation may be expensive for collections that have a large amount of data and/or a large number of indexes.For most users, the reIndex command is unnecessary. However, it may be worth running if the collection size has changed significantly or if the indexes are consuming a disproportionate amount of disk space.

Call reIndex using the following form:

db.collection.reIndex();

Reference : https://docs.mongodb.com/manual/reference/method/db.collection.reIndex/

like image 119
Sumeet Kumar Yadav Avatar answered Jan 03 '23 10:01

Sumeet Kumar Yadav