Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can mongodb inserts be made faster using the $hint and $natural operators

Tags:

mongodb

I am aware that indexes slow down inserts as the indexes need to updated every time a new record is inserted.

For a collection with several indexes, is it possible to direct the insert operation to use the $hint operator and force it to use the $natural index ? Will this speed up the inserts or am I better off dropping all indexes just to speed up the inserts?

like image 410
Macky Avatar asked Jun 25 '13 11:06

Macky


1 Answers

that $natural hint is telling mongo to ignore indexes on queries, it has nothing with insertions.
please note that you cannot turn off the indexes for period of time.
If you want to speed up your insertions, dropping your indexes is an option but it will affect your queries. a better option is to change the write concerns setting:
for instance, "Unacknowledged" will make the insertion faster as it won't wait for mongod to confirms the receipt of the write operation. I guess that the downside is clear.
take a look here: http://docs.mongodb.org/manual/core/write-concern/

About indexes, it's never a good idea to have indexes that you don't need as they are slowing down insertions (as you already know) and they are biting your machine memory.

At the documentation, it is recommended to use capped collections to speed up the writes, you may want to consider it.

like image 170
Tamir Avatar answered Sep 21 '22 10:09

Tamir