MongoDB C++ Driver
legacy-1.1.2
|
Class for constructing and executing bulk operations against MongoDB via a fluent API. More...
#include <bulk_operation_builder.h>
Public Member Functions | |
BulkOperationBuilder (DBClientBase *const client, const std::string &ns, bool ordered, bool bypassDocumentValidation=false) | |
BulkOperationBuilder constructor. More... | |
BulkUpdateBuilder | find (const BSONObj &selector) |
Supplies a filter to select a subset of documents on which to apply an operation. More... | |
void | insert (const BSONObj &doc) |
Enqueues an insert write operation to be executed as part of the bulk operation. More... | |
void | execute (const WriteConcern *writeConcern, WriteResult *writeResult) |
Executes the bulk operation. More... | |
Class for constructing and executing bulk operations against MongoDB via a fluent API.
Example Usage:
BulkOperationBuilder bulk(...); bulk.insert(<BSONObj>); bulk.insert(<BSONObj>); bulk.find(<BSONObj>).updateOne(<BSONObj>);
vector<BSONObj> results; bulk.execute(<WriteConcern>, &results);
Usually not instantiated directly, instead it usually comes into being via the following DBClientBase methods:
initializeOrderedBulkOperation() intiializeUnorderedBulkOperation()
The class is able to optimize unordered operations by grouping similar ones into batches instead of sending them individually to the server. This means that unordered writes are non-deterministic. This is by design.
mongo::BulkOperationBuilder::BulkOperationBuilder | ( | DBClientBase *const | client, |
const std::string & | ns, | ||
bool | ordered, | ||
bool | bypassDocumentValidation = false |
||
) |
BulkOperationBuilder constructor.
DBClientBase::initializeOrderedBulkOperation will set ordered to true DBClientBase::initializeUnorderedBulkOperation will set ordered to false
client | The connection to use. |
ns | The namespace to apply the operations to. |
ordered | Whether or not ordering matters for these operations. param bypassDocumentValidation Whether to bypass document validation for these operations, |
void mongo::BulkOperationBuilder::execute | ( | const WriteConcern * | writeConcern, |
WriteResult * | writeResult | ||
) |
Executes the bulk operation.
wc | The Write concern for the entire bulk operation. 0 = default (acknowledged); |
results | Vector where the results of operations will go. |
BulkUpdateBuilder mongo::BulkOperationBuilder::find | ( | const BSONObj & | selector | ) |
Supplies a filter to select a subset of documents on which to apply an operation.
The operation that is ultimately enqueued as part of this bulk operation depends on the subsequent method calls made to the returned BulkWriteOperation object.
selector | A BSONObj that describes the objects to modify. |
void mongo::BulkOperationBuilder::insert | ( | const BSONObj & | doc | ) |
Enqueues an insert write operation to be executed as part of the bulk operation.
doc | The document to enqueue. |