From 71e3aa7683ce5d0310b33869509418402f451d14 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Mon, 2 Sep 2024 21:18:58 +0200 Subject: [PATCH] MongoDB: Improve reading timestamps in previous BSON formats bson.errors.InvalidBSON: year 292278994 is out of range Consider Using CodecOptions(datetime_conversion=DATETIME_AUTO) or MongoClient(datetime_conversion='DATETIME_AUTO'). See: https://pymongo.readthedocs.io/en/stable/examples/datetimes.html#handling-out-of-range-datetimes --- CHANGES.md | 1 + cratedb_toolkit/io/mongodb/core.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 2cad8c2..0d4d135 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ ## Unreleased - MongoDB: Rename columns with leading underscores to use double leading underscores - MongoDB: Add support for UUID types +- MongoDB: Improve reading timestamps in previous BSON formats ## 2024/09/02 v0.0.21 - DynamoDB: Add special decoding for varied lists. diff --git a/cratedb_toolkit/io/mongodb/core.py b/cratedb_toolkit/io/mongodb/core.py index 7e1744e..5a34207 100644 --- a/cratedb_toolkit/io/mongodb/core.py +++ b/cratedb_toolkit/io/mongodb/core.py @@ -57,7 +57,7 @@ def gather_collections(database) -> t.List[str]: def get_mongodb_client_database(args, **kwargs) -> t.Tuple[pymongo.MongoClient, pymongo.database.Database]: client: pymongo.MongoClient - client = pymongo.MongoClient(args.url, **kwargs) + client = pymongo.MongoClient(args.url, datetime_conversion="DATETIME_AUTO", **kwargs) db: pymongo.database.Database = client.get_database(args.database) return client, db