我想在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']]]
);
}
如何在单个查询中执行此操作?