在Pymongo检查现场存在

时间:2017-01-05 16:37:37

标签: python mongodb pymongo

我有一个这样的集合:

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

我想找到我所有的文件和#34; City"不存在。 我试试:

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

我有这条错误消息:

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

1 个答案:

答案 0 :(得分:6)

您将三个参数传递给find方法。我假设您打算仅通过过滤器和投影。试试这个:

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