简体   繁体   English

Mongo PHP查询中的$ not运算符

[英]$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? 我做错了什么?

  • PHP mongo extension Version => 1.4.5 PHP mongo扩展版本=> 1.4.5
  • PHP => Version => 5.5.9 PHP =>版本=> 5.5.9
  • MongoDB shell version: 2.4.9 MongoDB Shell版本:2.4.9

Simply use the $nor operator. 只需使用$nor运算符。

$nor performs a logical NOR 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM