Is moped's (Ruby mongodb driver) remove_all operation a background operation?

163 Views Asked by At

It returns immediately and I'm not entirely sure what the expected behavior is. Is it removing in the background?

http://mongoid.org/en/moped/

1

There are 1 best solutions below

0
On

The code that performs this operation in Moped is definitely not asynchronous and it will block while the operation is being sent to MongoDB (and potentially, by default, while waiting for a response from the database).

https://github.com/mongoid/moped/blob/master/lib/moped/query.rb#L290-L307 https://github.com/mongoid/moped/blob/master/lib/moped/node.rb#L466-L468

However, as Chris Heald has already alluded too, if you use a write concern of w=0 (the so called "fire-and-forget" mode) this tells Moped not to wait around for a response from the server. You won't receive confirmation that the remove_all completed successfully but you can effectively background the work to your MongoDB server through this method.

Here's some more info on how MongoDB's write-concerns work for unacknowledged writes: http://docs.mongodb.org/manual/core/write-concern/#unacknowledged