MongoDB查询

1、为null或者不存在

db.test.find({"test":null});

2、不为null并且存在记录

db.test.find({"test":{"$ne":null}});
db.test.find({"test":{"$ne":null, $exists:true}});

3.存在

db.test.find({"test":{$exists:true}});

4.不存在(不会返回null的值)

db.test.find({"test":{$exists:false}});

 

 # for i in db.find({"title":{"$nin":["",None]}},{"_id":False,"title":True}):  # 过滤即不等空字符串又不等于None
    for i in db.find({"title":{"$ne":""}},{"_id":False,"title":True}): # 过滤不等于空字符串
        f.write(str(i["title"]) + "\n")

 

posted @ 2019-11-28 15:57  睡觉了嘛  阅读(150)  评论(0编辑  收藏  举报