2015-11-15

MongoDB - Filter on a given field, if it exists




db.COLLECTION_NAME.find(
    $or: [
        { FIELD_NAME : { $exists : false}}
        , { FIELD_NAME : EXACT_VALUE_TO_COMPARE_TO }
    ]
);


db.COLLECTION_NAME.find(
    FIELD_NAME : { $ne : EXACT_VALUE_TO_COMPARE_TO }
);



No comments:

Post a Comment