0

I have a Mongo database storing information about some weather stations. For example:

{ 
    "_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
        ]
    }
}

In order to find the records with empty "Station end date" I do the following query in Mongodb and it works:

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

However, using pymongo I tried without success. In theory, this should work, but it doesn't:

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

It always returns an empty result. Any ideas of how can this be sorted?

2
  • Works for me. Just inserted your document and even used the same collection name and copied the query from here. Returns the document without a problem. You are probably in the wrong database namespace. Commented Apr 25, 2018 at 12:22
  • I just noticed I was connected to the same database but with different content. The code is working fine. I should sleep more. Commented Apr 25, 2018 at 12:26

1 Answer 1

1

The code works just fine. The problem was that I was connected to a different database, containing the data before it was prepared. Shame on me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.