开发者

Mongo DB $or query in PHP

I can't figure out for the life of my to select from a collection with the or parameter. It's not working at all for me and I can't really find any documentation on it for 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"
        )
    )
);


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")
)));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜