如何在mongoDB PHP中一次更新多个字段?

时间:2017-06-02 23:19:07

标签: php mongodb

我想在php页面中的mongo中进行更新查询,一次更新多个字段,我用这种方式尝试了updateOne:

$collection->updateOne(
    ['_id' => new MongoDB\BSON\ObjectID($data['_id'])],
    ['$set' => ['name' => $data['name']]],
    ['$set' => ['owner' => $data['owner']]]
);

但不起作用

现在我让它在两个单独的查询中工作

$collection->updateOne(
    ['_id' => new MongoDB\BSON\ObjectID($data['_id'])],
    ['$set' => ['name' => $data['name']]]
);
}

$collection->updateOne(
    ['_id' => new MongoDB\BSON\ObjectID($data['_id'])],
    ['$set' => ['owner' => $data['owner']]]
);
}

如何在单个查询中执行此操作?

0 个答案:

没有答案