0
我使用PHP和mongodb。我想使用findandmodify。我的字段是{“_id”:ObjectId(“58d37e612d4ffa498b99c2d4”),“userid”:“1234”,“active_time”:“hai”}php mongodb findandmodify不工作
我想修改active_time。例如,将值“hai”更改为“1234”
我正在使用MongoDB \ Driver \ Manager。
try {
$mng = new MongoDB\Driver\Manager("mongodb://username:[email protected]:27017/db");
$userid = '1234';
$retval = $mng->findAndModify(
array("userid" => $userid), // searchQuery
array('$set' => array('active_time' => "kkk")) // UpdateQuery
);
$command = new MongoDB\Driver\Command($retval);
$cursor = $manager->executeCommand('db.online', $command);
} catch (MongoDB\Driver\Exception\Exception $e) {
$filename = basename(__FILE__);
echo "The $filename script has experienced an error.\n";
echo "It failed with the following exception:\n";
echo "Exception:", $e->getMessage(), "\n";
echo "In file:", $e->getFile(), "\n";
echo "On line:", $e->getLine(), "\n";
}
它显示了错误
致命错误:未捕获的错误:调用未定义的方法的MongoDB \驱动程序\管理:: findAndModify()
符合$retval = $mng->findAndModify(
array("userid" => $userid), // searchQuery
array('$set' => array('active_time' => "kkk")) // UpdateQuery
);
如何有可能吗?请帮帮我?
有没有函数调用findAndModify(); http://php.net/manual/en/book.mongodb.php –
我得到了答案。看到我的答案。 – Fazil