Skip to content

Documentation - Bulk update - only first matching document gets updated. Required "multi" flag missing. #229

@andzandz

Description

@andzandz

In the bulk documentation file/page:
https://github.com/mongodb/mongo-php-driver/blob/master/docs/bulk.md
http://mongodb.github.io/mongo-php-driver/bulk/

These example queries:

$bulk->update(
    ["_id" => $hayley_id],
    ['$set' => ["citizen" => "Iceland"]],
    ["limit" => 1, "upsert" => false]
);
$bulk->update(
    ["citizen" => "Iceland"],
    ['$set' => ["viking" => true]],
    ["limit" => 0, "upsert" => false]
);
$bulk->update(
    ["name" => "Chuck Norris"],
    ['$set' => ["viking" => false]],
    ["limit" => 1, "upsert" => true]
];

All of these will only update the first matching document. The "limit" => 0 in the second update() call clearly implies updating multiple documents (one for each Icelandic citizen)

The multi flag (required to be true to update multiple documents) defaults to false: http://php.net/manual/en/mongodb-driver-bulkwrite.update.php

This fixed query will update multiple documents:

$bulk->update(
    ["citizen" => "Iceland"],
    ['$set' => ["viking" => true]],
    ["limit" => 0, "upsert" => false, "multi" => true]
);

Please add the multi flag to the documentation. Thanks!

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