Reputation: 812
I have read about indexing in DB, the point i don't understand is that why do we need to specify index to a particular column, if it makes the search fast, why it is not by default to all columns? is it possible to create multiple indexes in one table?
Upvotes: 1
Views: 355
Reputation: 4363
To resume :
Using indexes improves performances on read query, because mongodb doesn't read entire collection when searching documents. It also improves sorting.
But these improvments have a cost :
For these reasons (but not only), by default only index on _id field (as it need to be unique) is created on collection creation.
Upvotes: 2
Reputation: 990
If there are n no. of indices and when you perform any save/update operation that modifies keys, it does it n times, hence produces an excessive write lock. When you will perform such operation, you will observe that reads would be faster with no indexes than when trying to update consistently with too many indexes. So in order to perform indexing, you should keep track of indexes else there would be a great performance issue (sake of RAM and write lock).
Upvotes: 1