将MongoDB对象从updateOne转换为PHP数组
我在PHP中从var_dump()输出的结果显示了updateOne MongoDB命令对集合的结果:将MongoDB对象从updateOne转换为PHP数组,php,mongodb,Php,Mongodb,我在PHP中从var_dump()输出的结果显示了updateOne MongoDB命令对集合的结果: object(MongoDB\UpdateResult)#136 (2) { ["writeResult":"MongoDB\UpdateResult":private] => object(MongoDB\Driver\WriteResult)#135 (9) { ["nInserted"]=> int(0) ["nMatched"
object(MongoDB\UpdateResult)#136 (2) {
["writeResult":"MongoDB\UpdateResult":private] => object(MongoDB\Driver\WriteResult)#135 (9) {
["nInserted"]=> int(0)
["nMatched"]=> int(0)
["nModified"]=> int(0)
"nRemoved"]=> int(0)
["nUpserted"]=> int(0)
["upsertedIds"]=> array(0) { }
["writeErrors"]=> array(0) { }
["writeConcernError"]=> NULL
["writeConcern"]=> array(4) {
["w"]=> NULL
["wmajority"]=> bool(false)
["wtimeout"]=> int(0)
["journal"]=> NULL
}
}
["isAcknowledged":"MongoDB\UpdateResult":private]=> bool(true)
}
我的问题是,如何将其转换为PHP并访问“nMatched”和“nInserted”的值?您可以直接使用返回的对象。 要访问匹配项,您可以执行以下操作:
$result->getMatchedCount();
adn用于插入的:
$result->getUpsertedCount();
这是正确且最简单的方法。
您可以将其用作参考,因为有一个名为getMatchedCount
的方法来获取nMatched
值,但是对于插入的n
,似乎没有等效的方法,这可能有意义,因为这是一个UpdateResult
,并且只有修改的值。