我正在使用新的PHP Mongo驱动程序来执行批量更新操作。 文档在集合中更新,但nModified值始终为null。
use MongoDB\Driver\BulkWrite;
use MongoDB\Driver\Query as MongoDbQuery;
use MongoDB\Driver\Manager as MongoDbManager;
class Offers {
const NS = 'ecommerce_v2.products';
public function insert($offer, $merchant, $scope) {
$manager = new MongoDbManager();
$bulk = new BulkWrite();
$filter = [
'merchants_id' => (int) $merchant,
'external_reference' => ['$in' => $scope]
];
$bulk->update($filter, ['$set' => ['offer' => $offer]], ['multi' => true]);
// MongoDB\Driver\WriteResult
$result = $manager->executeBulkWrite(static::NS, $bulk);
// NULL
return $result->getModifiedCount();
}
}
有什么想法吗?