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
The pymongo version of null is the Python None. So query should look like:
query = {
'Name': {'$regex': search_title, '$options': 'i'},
'Images.SmallUrl': {'$ne': None}}
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 ^_^