There are two things that you can do.
- Send an update with the ‘multi’ flag set to true.
- Store the function server-side and try using server-side code execution.
That link also contains the following advice:
This is a good technique for performing batch administrative work. Run mongo on the server, connecting via the localhost interface. The connection is then very fast and low latency. This is friendlier than db.eval() as db.eval() blocks other operations.
This is probably the fastest you’ll get. You have to realize that issuing 9M updates on a single server is going to be a heavy operation. Let’s say that you could get 3k updates / second, you’re still talking about running for nearly an hour.
And that’s not really a “mongo problem”, that’s going to be a hardware limitation.