gpt4 book ai didi

php - MongoDB $或PHP中的查询

转载 作者:IT老高 更新时间:2023-10-28 13:07:21 25 4
gpt4 key购买 nike

我一辈子都想不通如何从带有 or 参数的集合中进行选择。它对我来说根本不起作用,我真的找不到任何关于它的 php 文档。

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

$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.

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

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

关于php - MongoDB $或PHP中的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7451684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com