$collection->update(array("_id"=>new MongoId($uid), "phonenumber"=> $exist => array(FALSE),$set("phone"=>"1223444"));
我想知道为什么我的 $exist 查询不能与 PHP 和 Mongodb 一起工作,如果有人能指出正确的方向会有所帮助的话。
好的,在集合数据库中没有名为 phonenumber 的行,如果没有 phonenumber 我希望它插入一个,但如果有 phonenumber 则不做任何事情。
最佳答案
你有几个语法问题。
- 你缺少二级数组
- 您的运算符需要用单引号括起来 (
$exist
)
这是一个清理后的示例:
$collection->update(
array( "_id"=> new MongoId($uid),
array("phonenumber"=> array('$exists' => false))
),
array( '$set' => array("phone"=>"1223444") )
);
关于PHP MongoDB $exist 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11489297/