PHP MongoDB $exist 不工作

标签 php mongodb exslt

$collection->update(array("_id"=>new MongoId($uid), "phonenumber"=> $exist => array(FALSE),$set("phone"=>"1223444"));

我想知道为什么我的 $exist 查询不能与 PHP 和 Mongodb 一起工作,如果有人能指出正确的方向会有所帮助的话。

好的,在集合数据库中没有名为 phonenumber 的行,如果没有 phonenumber 我希望它插入一个,但如果有 phonenumber 则不做任何事情。

最佳答案

你有几个语法问题。

  1. 你缺少二级数组
  2. 您的运算符需要用单引号括起来 ($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/

相关文章:

xml - 我们如何在不下载其源代码的情况下使用 EXSLT?

database - 从 MongoDB Atlas 迁移我的数据

xslt - 结果树片段背后的基本原理是什么?

php - 带有 PHP、html 格式的电子邮件确认电子邮件

php - 有关安全环境中用户的最佳实践/操作指南

python - 使用Python创建MongoDb数据库

javascript - Mongo/mongoose $facet 过滤器,如果客户应用过滤器,则返回所有产品的品牌/标签作为响应

javascript - 如何使 XSLT Javascript 扩展函数返回节点集?

php - 传递无效参数类型时显示异常消息

php - nginx : Resource interpreted as Stylesheet but transferred with MIME type text/html 无法识别 css 和图像