I am using PyMongo to simply iterate over a Mongo collection, but I'm struggling with handling large Mongodb date objects.
For example, if I have some data in a collection that looks like this:
"bad_data" : [
{
"id" : "id01",
"label" : "bad_data",
"value" : "exist",
"type" : "String",
"lastModified" : ISODate("2018-06-01T10:04:35.000Z"),
"expires" : Date(9223372036854775000)
}
]
I will do something like:
from pymongo import MongoClient, database, cursor, collection
client = MongoClient('localhost')
db = client['db1']
db.authenticate('user', 'pass', source='admin')
collection = db['collection']
for i in collection:
# do something with i
and get the error InvalidBSON: year 292278994 is out of range
Is there any way I can handle dealing with this rediculous Date()
object without bson falling over? I realise that having such a date in Mongodb is crazy but there is nothing I can do about this as it's not my data.
InvalidBSON
by calling the__getitem__
function. – Goins