I have a collection where some of the objects feature an key foo. I now try to query for all objects that indeed have this key but not with the specific value <
foo
You can use $and to join multiple conditions:
$and
collection.find({"$and": [{"foo": {'$ne': 'bar'}}, {"foo": {'$exists': True}}]})
No necessary to use $and, it also works
db.collection.find({"foo":{"$ne":"bar", "$exists":true}})