masber
masber

Reputation: 3067

Mongodb and PHP $and query

the following query is not working for me in PHP, I need help finding out what is wrong with it, I have check other examples and still don't know how to fix it...

$query = array(
    "Client"        => $notificationJob['Client'],
    "Email"         => $notificationJob['Email'],
    "Backup Type"   => $notificationJob['Backup Type'],
    array ( "$and"  => 
        array(
            array( "Message Subject" => new MongoRegex('/'. preg_quote($notificationJob['MessageSubject string1']). '/i') ),
            array( "Message Subject" => new MongoRegex('/'. preg_quote($notificationJob['MessageSubject string2']). '/i') )
        )
    ),

    "Time Stamp"    => array('$lte'=>New Mongodate($startDate->getTimestamp()))
);

The error I am getting is:

Notice: Undefined variable: and in ...

thank you very much

Upvotes: 0

Views: 69

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191819

Use '$and'. Variables in double-quotes are interpolated.

You could also use "\$and"

Upvotes: 2

Related Questions