Adapter to write documents from a queue to mongodb concurrently
MongoWriter provides a simple interface to write documents to a mongodb replica set. The interface is an object which behaves like a queue, MongoWriter being the consumer. It tries to handle mongo exceptions (like primary change) gracefully, only dropping documents if the input queue gets full. This is to make a best effort to insert the latest documents in the face of overload or errors but can be disabled by using an unlimited queue.
By default MongoWriter uses Threads for its insert workers. Using monkey patches, it works with greenlets as well.
The input object passed to MongoWriter can be anything that acts like a Python queue. The items in the queue are expected to be (collection_name, document) tuples. There is a queue adaptation in mongowriter.util which can be useful for high troughput writing to capped collections.