duanji2772 2014-02-16 16:57
浏览 16
已采纳

MongoDB或范围的运营商


This is the range Im using :

$Range1=array('$or'=>array(
                array( '$gte' =>  floatval($O_NLA), '$lte' => $N_NLA ),
                array( '$gte' =>  floatval($N_SLA), '$lte' => $O_SLA ))
                );
$Range2=array('$or'=>array(
                array( '$gte' =>  floatval($N_SLO), '$lte' => $O_SLO ),
                array( '$gte' =>  floatval($O_NLO), '$lte' => $N_NLO ))
                );

A part of my query :

$finder=$reposit->findBy(
                                                array(
                                                'field1' => $Range1,
                                                'field2' => $Range2,
                                                'display'=>1
                                                ))->toArray();

"message":"localhost:27017: invalid operator: $or"..... (it's long though)

How can I use $or operator with doctrine without query builder?

  • 写回答

1条回答 默认 最新

  • doukeng1922 2014-02-16 17:41
    关注
    findBy([
        '$or' => [
            ['field1' => ['$gte' =>  floatval($O_NLA), '$lte' => $N_NLA]],
            ['field1' => ['$gte' =>  floatval($N_SLA), '$lte' => $O_SLA]],
            ['field2' => ['$gte' =>  floatval($N_SLO), '$lte' => $O_SLO]],
            ['field2' => ['$gte' =>  floatval($O_NLO), '$lte' => $N_NLO]]
        ]
        , 'display' => 1
    ])
    

    Or actually:

    findBy([
        '$and' => [
            ['$or' => [
                ['field1' => ['$gte' =>  floatval($O_NLA), '$lte' => $N_NLA]],
                ['field1' => ['$gte' =>  floatval($N_SLA), '$lte' => $O_SLA]],
            ]],
            ['$or' => [
                ['field2' => ['$gte' =>  floatval($N_SLO), '$lte' => $O_SLO]],
                ['field2' => ['$gte' =>  floatval($O_NLO), '$lte' => $N_NLO]]
            ]]
        ]
        , 'display' => 1
    ])
    

    To be more precise according to your question.

    Since the $or works upon condition which then contains a find() like array.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法