这是我使用的范围:
$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 ))
);
我查询的一部分:
$finder=$reposit->findBy(
array(
'field1' => $Range1,
'field2' => $Range2,
'display'=>1
))->toArray();
"消息":"本地主机:27017:无效运算符:$or".....(虽然很长)
如何在没有查询生成器的情况下将$or运算符与原则一起使用?
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
])
或者实际上:
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
])
根据您的问题更准确。
由于$or
在条件下工作,然后包含一个类似find()
数组。