PHP中的MongoDB $和运算符查询 [英] MongoDB $and operator query in PHP
本文介绍了PHP中的MongoDB $和运算符查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用$ and运算符和MongoRegex时遇到了困难.
I've been having difficulty with the $and operator and MongoRegex.
我正在对"Amazon"进行正则表达式记录搜索,该搜索还将字段"enabled"设置为1.
I'm doing a regex record search for "Amazon" that also has the field "enabled" set to 1.
这是我的查询.
$search = "Amazon";
$results = $collection->find(array(
'$and' => array(
array('orgname' => new MongoRegex("/.*$search.*/")),
array('enabled' => '1')
)
));
也许有人可以指出我做错了什么. 预先感谢.
Maybe someone can point out what I'm doing wrong. Thanks in Advance.
推荐答案
我认为在这种情况下,您无需使用$and
运算符.试试这个:
I think that in this case you don't need to use the $and
operator. Try this:
$search = "Amazon";
$cursor = $collection->find(array(
'orgname' =>new MongoRegex("/.$search./"),
'enabled' => 1)
);
这篇关于PHP中的MongoDB $和运算符查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文