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

后端 未结 10 2307
暖寄归人
暖寄归人 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 16:57

    In an ideal case, you would like to test for all three values, null, "" or empty(field doesn't exist in the record)

    You can do the following.

    db.users.find({$and: [{"name" : {$nin: ["", null]}}, {"name" : {$exists: true}}]})
    

提交回复
热议问题