问题
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