How do you query for “is not null” in Mongo?

后端 未结 10 2298
暖寄归人
暖寄归人 2020-11-30 15:59

I would like to execute a following query:

db.mycollection.find(HAS IMAGE URL)

What should be the correct syntax?

10条回答
  •  长情又很酷
    2020-11-30 16:46

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

    fetch documents that contain this filed_name even it is null.

    Warning

    db.collection_name.find({"filed_name":{$ne:null}});
    

    fetch documents that its field_name has a value $ne to null but this value could be an empty string also.

    My proposition:

    db.collection_name.find({ "field_name":{$ne:null},$where:"this.field_name.length >0"})
    

提交回复
热议问题