Search code examples
c++mongodbmongo-cxx-driver

Mongo C++ bulk operations


How do I execute bulk operations with the new Mongocxx driver? The driver manual is horrible. And there are no examples anywhere!!!

Relevant class: http://mongodb.github.io/mongo-cxx-driver/api/mongocxx-3.1.1/classmongocxx_1_1bulk__write.html

I can create an operation using bulk_write::bulk_write() and add queries using bulk_write::append(). But I am confused as to how to execute it.

It's terrible that they don't provide similar functions like the mongo shell. Ex: https://docs.mongodb.com/manual/reference/method/Bulk/


Solution

  • Create a bulk_write instance, then populate it with write operations and finally submit it to Mongo collection using this method:

    collection::bulk_write(const bulk_write& bulk_write)