Logical Operators

$and -- true when all the conditions are true, else false.

$or -- true when at-least one condition is true, else false.

$not -- negation true/false

$nor -- true when all conditions are false, false otherwise.

/ age > 31 and location = NYC

db.friendsCollection.find(
    {
        $and:
            [
                {age : {$gt : 31}}
                ,{location: "NYC"}
            ]
    });

// Greater than or equal to 31 and name = Ross

db.friendsCollection.find(
    {
        $and:
            [
                {age : {$gte : 31}}
                ,{firstname: "Ross"}
            ]
    });

Last updated