Mongo DB $或PHP查询

And*_*rew 17 php find mongodb

我无法弄清楚我的生活从or参数中选择一个集合.它对我来说根本不起作用,我无法在php上找到任何关于它的文档.

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

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

Kar*_*ath 47

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.
Run Code Online (Sandbox Code Playgroud)

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

find(array('$or' => array(
  array("brand" => "anti-clothes"),
  array("allSizes" => "small")
)));
Run Code Online (Sandbox Code Playgroud)