0

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.

2
  • I edited your question and formatted in so it is easier to read. Perhaps it works now. I think you hade placed one ending bracket at the end instead of after new MongoRegex("/.*$search.*/"). But I cannot go back and see your orignal post... Anyway, in this case you don't need the $and operator, see my anwer. Commented Jul 21, 2013 at 8:48
  • @luttkens If you changed the code then you changed the nature of the question, that incorrect bracket could have been the problem... Commented Jul 21, 2013 at 9:12

1 Answer 1

2

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)
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.