我浏览了文档,但没有关注如何对单个文档执行更新。
$db = \core\databaseUtilities\getDbConnection();
$filter = [ '_id' => new \MongoDB\BSON\ObjectID($user->_id)];
$bulk = new \MongoDB\Driver\BulkWrite;
$options=array('multi' => false, 'upsert' => false);
$bulk->update($filter, $user, $options);
$db->executeBulkWrite($db->dbName.'.users', $bulk);
return $user;
$ db的类型为\ MongoDB \ Driver \ Manager
我得到这个例外:
替换参数无效:键不能以“ $”开头:“ $ oid””
我的文档看起来像这样,这是以前创建它的方式。
{
"_id": {
"$oid": "5c6bb2678cbee451d40019e7"
},
"firstName": "Maria",
"lastName": "Rambo",
"email": "warrior@gmail.com",
"password": "password"
}