且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如果字段不存在,则 mongodb 更新

更新时间:2021-12-05 09:10:01

我认为您需要在这里进行两个单独的查询.这对于 MongoDB 查询解析器来说太有条件了.

I think you will need to do two separate queries here. That is just too conditional for MongoDB query parser to handle.

因此,您需要将逻辑放入两个单独的查询中,第二个查询如下所示:

So you will need to put your logic into two separate queries with the second looking like:

$db->akis->update(
array("h" => (string) $_SESSION["_id"], "m" => array('$exists' => true)),
array('$set' => array("i" => $name)),
array("multiple" => true)
);

一个接一个地运行.