MongoDB $and operator query in PHP

谁都会走 提交于 2019-12-30 16:37:13

问题


I've been having difficulty with the $and operator and MongoRegex.

I'm doing a regex record search for "Amazon" that also has the field "enabled" set to 1.

This is my query.

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


回答1:


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


来源:https://stackoverflow.com/questions/17769609/mongodb-and-operator-query-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!