使用pymongo在Mongodb中查找空记录

时间:2018-04-25 12:09:30

标签: mongodb pymongo

我有一个Mongo数据库,存储有关某些气象站的信息。例如:

{ 
    "_id" : ObjectId("5ae052a739027d186162ed50"), 
    "src_id" : NumberInt(55844), 
    "Name" : "ABERDEEN: NIGG HEAD WORKS", 
    "Area" : "ABERDEENSHIRE", 
    "Area type" : "COUNTY", 
    "Station start date" : ISODate("1997-03-01T00:00:00.000+0000"), 
    "Station end date" : null, 
    "Postcode" : "AB12", 
    "loc" : {
        "type" : "Point", 
        "coordinates" : [
            -2.06163, 
            57.1318
        ]
    }
}

为了找到空"Station end date"的记录,我在Mongodb中执行以下查询并且它有效:

db.MIDAS_stations.find({
    "Station end date" : null
})

然而,使用pymongo我尝试没有成功。从理论上讲,这应该有效,但它没有:

returned_location = db.MIDAS_stations.find(
    {
        "Station end date" : None
    }
)
print(list(returned_location))

它总是返回一个空结果。关于如何分类的任何想法?

1 个答案:

答案 0 :(得分:1)

代码工作得很好。问题是我连接到一个不同的数据库,包含准备之前的数据。对我感到羞耻。