Pymongo使用$存在

时间:2014-11-12 19:43:54

标签: python mongodb pymongo

我是pymongo的新手并且在使用存在时遇到了麻烦。使用collection.find({},{"cwc":{"$exists": True}})时,我收到以下错误Unsupported projection option: $exists

我想要完成的是找到所有'_id'和'cwc',其中'cwc'存在而不是空。

2 个答案:

答案 0 :(得分:5)

这适合我。

collection.find({"cwc":{"$exists":True}})

唯一的区别是删除了第一个参数。

答案 1 :(得分:2)

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