You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 14, 2020. It is now read-only.
Currently there doesn't seem to be a way to properly parse mongodb extended json datetimes into a document with from_json. As an example consider this extended json document:
However, parsing the date fails since mongokit/document.py:586 just calls fromtimestamp with the whole {"$date".. dict as an argument. This could be solved by using a structure where "time": {"$date": datetime.datetime}, but this doesn't work since keys starting with $ are not allowed.
It seems to me it would be optimal if mongokit would be able to parse the standard mongodb extended json out of the box - for a variety of reasons. Thus it would probably make sense to either replace line 586 with doc[key] = fromtimestamp(doc[key]["$date"]) , (just like is done with $oid for objectid fields or $db and $ref) or if there are fears of breaking backwards compatibility by checking the type of doc[key] and whether there is a $date key if it is a dict. I can fork and make a pull request if you agree with my reasoning.
On a related note, since mongodb 2.6 the extended json format also uses ISO datetime strings instead of milliseconds since epoch - so the current parser fails there as well.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Currently there doesn't seem to be a way to properly parse mongodb extended json datetimes into a document with from_json. As an example consider this extended json document:
The id is properly parsed with a structure as follows:
However, parsing the date fails since mongokit/document.py:586 just calls fromtimestamp with the whole {"$date".. dict as an argument. This could be solved by using a structure where "time": {"$date": datetime.datetime}, but this doesn't work since keys starting with $ are not allowed.
It seems to me it would be optimal if mongokit would be able to parse the standard mongodb extended json out of the box - for a variety of reasons. Thus it would probably make sense to either replace line 586 with doc[key] = fromtimestamp(doc[key]["$date"]) , (just like is done with $oid for objectid fields or $db and $ref) or if there are fears of breaking backwards compatibility by checking the type of doc[key] and whether there is a $date key if it is a dict. I can fork and make a pull request if you agree with my reasoning.
On a related note, since mongodb 2.6 the extended json format also uses ISO datetime strings instead of milliseconds since epoch - so the current parser fails there as well.
The text was updated successfully, but these errors were encountered: