Mongodb server becomes slow when cleanup of documents

We observed mongo db was slow when there is delete/cleanup of documents. Total number doc was 20M.
Is there configuration/setting to make read operation to be timeout quickly in production environment.
using 3.5.9 version.

Can you suggest the better approach for cleanup when db is used by customers.

Thanks

Hello @rajesh_kumar10

When you say version 3.5.9 what are you referring to?

I am not aware of a MongoDB release 3.5.9 (if there was, it would be well past end-of-life at this point) do you mean the Node driver?

That said, it is rather hard to answer without more details, but a few ideas to consider:

  1. What sort of query are you using to delete?

  2. Do you have an index on whatever field you are using to delete the documents? If you don’t MongoDB will need to do a collection scan, and that is very slow.

  3. You could look into using a Bulk operation like Bulk.find.remove()

3.5.9 is node driver. Thanks for you suggestion, i will look into that

1 Like