Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check Field Exist in Pymongo

I have a collection like this :

{ 
  "_id":"1321464"
  "Sex":"Male"
  "Age":"20" 
  "City":"Toronto" #Maybe this field are not present.
}

I want to find all my document with the field "City" not exist. I try :

collection.find({"sex":"Male"},{"City":{"$exists": False}},{'Age': 1, '_id':0})

And i have this error message :

File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 1239, in find
    return Cursor(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line 125, in __init__
    raise TypeError("skip must be an instance of int")
TypeError: skip must be an instance of int
like image 488
LionelF Avatar asked Jan 05 '17 16:01

LionelF


1 Answers

You're passing three arguments to the find method. I assume you intended to pass a filter and a projection only. Try this:

collection.find({"sex":"Male", "City":{"$exists": False}},{'Age': 1, '_id':0})
like image 158
Steve Rossiter Avatar answered Nov 05 '22 06:11

Steve Rossiter