MongoDB C++ Driver legacy-1.0.0
Loading...
Searching...
No Matches
Public Member Functions | List of all members
mongo::BulkOperationBuilder Class Reference

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)
 BulkOperationBuilder constructor.
 
BulkUpdateBuilder find (const BSONObj &selector)
 Supplies a filter to select a subset of documents on which to apply an operation.
 
void insert (const BSONObj &doc)
 Enqueues an insert write operation to be executed as part of the bulk operation.
 
void execute (const WriteConcern *writeConcern, WriteResult *writeResult)
 Executes the bulk operation.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ BulkOperationBuilder()

mongo::BulkOperationBuilder::BulkOperationBuilder ( DBClientBase *const  client,
const std::string &  ns,
bool  ordered 
)

BulkOperationBuilder constructor.

DBClientBase::initializeOrderedBulkOperation will set ordered to true DBClientBase::initializeUnorderedBulkOperation will set ordered to false

Parameters
clientThe connection to use.
nsThe namespace to apply the operations to.
orderedWhether or not ordering matters for these operations.

Member Function Documentation

◆ execute()

void mongo::BulkOperationBuilder::execute ( const WriteConcern writeConcern,
WriteResult writeResult 
)

Executes the bulk operation.

Parameters
wcThe Write concern for the entire bulk operation. 0 = default (acknowledged);
resultsVector where the results of operations will go.

◆ find()

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.

Parameters
selectorA BSONObj that describes the objects to modify.
Returns
BulkWriteOperation A BulkWriteOperation with the selector specified.

◆ insert()

void mongo::BulkOperationBuilder::insert ( const BSONObj doc)

Enqueues an insert write operation to be executed as part of the bulk operation.

Parameters
docThe document to enqueue.

The documentation for this class was generated from the following file: