Skip to content

Correct usage of options array on executeBulkWrite #780

@gmsantos

Description

@gmsantos

Description

Before version 1.4 I used to execute a bulk write for a heavy process with write concern 0. This process is chunked in some parts to avoid memory size exhaust in big MongoDB\Driver\BulkWrite objects.

$manager = new MongoDB\Driver\Manager();

for ($j = 0; $j <= 40; $j++) {
    $bulkWrite = new MongoDB\Driver\BulkWrite(['ordered' => false]);

    for ($i=0; $i < 90000; $i++) {
        $bulkWrite->update(
            [
                '_id' => rand(88888888, 99999999)
            ],
            [
                '$set' => [
                    'name' => 'GMSantos', 
                    'rand' => rand(0, 100000)
                ]
            ],
            [
                'upsert' => true
            ]
        );
    }

    $manager->executeBulkWrite(
        'db.some_collection',
        $bulkWrite,
        new MongoDB\Driver\WriteConcern(0)
    );
}

After upgrade to 1.4 driver, I noticed that chunks started to have a big delay in almost an hour, like writeConcern(0) was ignored. Even using the new options array this delay persisted:

$manager->executeBulkWrite(
    'db.some_collection',
    $this->getChunkedBulkWrite(),
    ['writeConcern' => new MongoDB\Driver\WriteConcern(0)]
);

But skipping the third argument or using a non associative array eliminated that delay:

$manager->executeBulkWrite(
    'db.some_collection',
    $this->getChunkedBulkWrite(),
    [new MongoDB\Driver\WriteConcern(0)] 
);

// or 

$manager->executeBulkWrite(
    'db.some_collection',
    $this->getChunkedBulkWrite()
);

What is the correct usage of $options argument? Is write concern 0 the default for executeBulkWrite on Manager?

Environment

mongodb -> 1.4.1
libbson bundled version => 1.9.2
libmongoc bundled version => 1.9.2
libmongoc SSL => enabled
libmongoc SSL library => OpenSSL
libmongoc crypto => enabled
libmongoc crypto library => libcrypto
libmongoc crypto system profile => disabled
libmongoc SASL => disabled
libmongoc compression => enabled
libmongoc compression snappy => disabled
libmongoc compression zlib => enabled

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions