Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb background task

If possible, i'd like to run a find & remove query on non-indexed columns in "background", without disturbing other tasks or exhausting memory to the detriment of others.

For indexing, there is a background flag. Can the same be appended for find/remove tasks?

Thanks for a tip

like image 988
ledy Avatar asked Feb 07 '13 11:02

ledy


2 Answers

This is not something you can use "background:true" for. Possibly the best way to handle this is to write a script that does this in the background. This script should run your operation in small batches with some delay in between. In pseudo code you would do:

  • find 10 docs you need to update
  • update those 10 docs
  • sleep
  • goto first step.

You will have to experiment with which value for sleep works. You do need to realize that all documents that you are updating need to be pulled into memory, so it will have at least some impact.

like image 199
Derick Avatar answered Oct 02 '22 09:10

Derick


No, there is not a background:true flag for this operation. The remove will yield when page faults occur and allow other operations to execute. If you need to throttle this, then you can either remove in smaller batches or use a find/remove pattern which will lower the impact to other operations.

like image 31
user602502 Avatar answered Oct 02 '22 11:10

user602502