Querying null value in MongoDB

后端 未结 2 964
执念已碎
执念已碎 2021-01-03 10:45

Using pymongo I am trying to retrieve the documents in a collection that have a SmallUrl different from null. I\'m trying to get t

2条回答
  •  青春惊慌失措
    2021-01-03 11:23

    your query does not work because you should use 'Images.SmallUrl' instead of 'SmallUrl' for the key of query. my test collection:

    > db.t.find()
    { "_id" : ObjectId("512cdbb365fa12a0db9d8c35"), "Images" : { "LargeUrl" : "http://aaa.com", "SmallUrl" : "http://bb.com" }, "Name" : "yy" }
    { "_id" : ObjectId("512cdc1765fa12a0db9d8c36"), "Images" : { "LargeUrl" : "http://aaa.com", "SmallUrl" : null }, "Name" : "yy" }
    

    and my test query:

    > db.t.find({'Images.SmallUrl': {$ne: null}})
    { "_id" : ObjectId("512cdbb365fa12a0db9d8c35"), "Images" : { "LargeUrl" : "http://aaa.com", "SmallUrl" : "http://bb.com" }, "Name" : "yy" }
    

    Hope to help ^_^

提交回复
热议问题