【问题标题】:Use mongo operator $and in Phalcon\Mvc\Collection在 Phalcon\Mvc\Collection 中使用 mongo 运算符 $and
【发布时间】:2017-04-26 02:42:25
【问题描述】:

我尝试使用 MongoDB 的运算符 $and 应用于 Phalcon\Mvc\Collection 如下:

   $documents = Staff::find( $condition);

数组 $condition 具有这样的“role”:

$condition["role"] = [
            "\$regex" => "$somevalue",  
            "\$and"=> [
                '$ne' => "admin" 
                ]     
            ];   

我得到这个错误

无法规范化查询:错误值:未知运算符:$and'

请帮我解决这个问题。
有没有更好的方法来为这个“role”应用多个条件?

【问题讨论】:

    标签: php mongodb operators phalcon odm


    【解决方案1】:

    $and 默认在 mongo 中使用。我认为只需"$ne" => "admin" 就足够了。

    MongoDB 在指定逗号时提供隐式 AND 操作 分隔的表达式列表。使用带有 $and 的显式 AND 当必须使用相同的字段或运算符时,运算符是必需的 在多个表达式中指定。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-07
      • 1970-01-01
      相关资源
      最近更新 更多