Mongodb $或PHP查询

时间:2011-09-17 00:41:49

标签: php mongodb find

我无法弄清楚我的生命是从具有or参数的集合中进行选择。它对我来说根本不起作用,我无法在php上找到任何关于它的文档。

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

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

1 个答案:

答案 0 :(得分:46)

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.

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

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