Question


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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top