MongoDB/PyMongo: Querying multiple criteria - unexpected results

前端 未结 2 782
离开以前
离开以前 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}}]})
    
    0 讨论(0)
  • 2020-12-31 14:17

    No necessary to use $and, it also works

    db.collection.find({"foo":{"$ne":"bar", "$exists":true}})
    
    0 讨论(0)
提交回复
热议问题