MongoDB/PyMongo: Querying multiple criteria - unexpected results

前端 未结 2 824
离开以前
离开以前 2020-12-31 13:28

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 <

2条回答
  •  悲哀的现实
    2020-12-31 13:55

    You can use $and to join multiple conditions:

    collection.find({"$and": [{"foo": {'$ne': 'bar'}}, 
                              {"foo": {'$exists': True}}]})
    

提交回复
热议问题