开发者

Mongo DB $or query in PHP

开发者 https://www.devze.com 2023-04-06 00:18 出处:网络
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.

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

精彩评论

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