Mongo DB $或PHP查询 [英] Mongo DB $or query in PHP
本文介绍了Mongo DB $或PHP查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法弄清楚我的生活是从集合中选择还是
参数。这对我来说根本不起作用,我也找不到任何有关php的文档。
这是我的示例代码,即使它们不返回任何东西存在于集合中:
$ $ p $ code $ $ cursor = $ products-> find(
array(
'
brand=>anti-clothes,
allSizes=>small
)
)
);
解决方案
$或运算符让你使用布尔值或在查询中。
给出$或一个表达式数组,其中任何一个都可以满足查询。
您只在数组中提供了一个元素。使用:
find(array('$ or'=> array(
array(brand=> ;anti-clothes),
数组(allSizes=>small)
)));
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")
)));
这篇关于Mongo DB $或PHP查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文