Mongo DB $ 或 PHP 中的查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7451684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:41:45  来源:igfitidea点击:

Mongo DB $or query in PHP

phpmongodbfind

提问by Andrew

I can't figure out for the life of my to select from a collection with the orparameter. It's not working at all for me and I can't really find any documentation on it for php.

我一生都无法从带有or参数的集合中进行选择。它对我来说根本不起作用,我真的找不到任何关于 php 的文档。

Here is my example code that doesn't return anything even though they exist in the collection:

这是我的示例代码,即使它们存在于集合中,也不返回任何内容:

$cursor = $products->find(
    array(
        '$or' => array(
            "brand" => "anti-clothes",
            "allSizes" => "small"
        )
    )
);

回答by Karoly Horvath

The $or operator lets you use boolean or in a query.
You give $or an array of expressions, any of which can satisfy the query.

You provided only one element in the array. Use:

您只提供了数组中的一个元素。用:

find(array('$or' => array(
  array("brand" => "anti-clothes"),
  array("allSizes" => "small")
)));