[英]$not operator in Mongo PHP query
I'm trying to write a query to Mongo DB with the following structure: 我正在尝试使用以下结构向Mongo DB编写查询:
not (condition1 or condition2)
$query = ['$or' => [$condition1, $condition2]];
works correctly, 正常工作
$query = ['$not' => ['$or' => [$condition1, $condition2]]];
is not working with error message invalid operator: $or' in ...
in logs. 不适用于错误消息
invalid operator: $or' in ...
中的invalid operator: $or' in ...
在日志中。 What I'm doing wrong? 我做错了什么?
Simply use the $nor
operator. 只需使用
$nor
运算符。
$nor
performs a logicalNOR
operation on an array of one or more query expression and selects the documents that fail all the query expressions in the array.$nor
在一个或多个查询表达式的数组上执行逻辑NOR
操作,并选择使数组中所有查询表达式均失败的文档。
$query = ['$nor' => [$condition1, $condition2]];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.