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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With