Skip to content

Commit

Permalink
fix(ingestion/mongodb): MongoDB source unable to parse datetimes with…
Browse files Browse the repository at this point in the history
… years > 9999
  • Loading branch information
JonasHan authored and jonasHanhan committed Mar 28, 2024
1 parent db668e8 commit 4b7dec1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions metadata-ingestion/src/datahub/ingestion/source/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from typing import Dict, Iterable, List, Optional, Tuple, Type, Union, ValuesView

import bson.timestamp
import pymongo
import pymongo.collection
from bson import CodecOptions, DatetimeConversion
from packaging import version
from pydantic import PositiveInt, validator
from pydantic.fields import Field
Expand Down Expand Up @@ -281,8 +281,11 @@ def __init__(self, ctx: PipelineContext, config: MongoDBConfig):
**options,
**self.config.options,
}
codec_options: CodecOptions = CodecOptions(
datetime_conversion=DatetimeConversion.DATETIME_AUTO
)

self.mongo_client = pymongo.MongoClient(self.config.connect_uri, **options) # type: ignore
self.mongo_client = MongoClient(self.config.connect_uri, codec_options=codec_options, **options) # type: ignore

# This cheaply tests the connection. For details, see
# https://pymongo.readthedocs.io/en/stable/api/pymongo/mongo_client.html#pymongo.mongo_client.MongoClient
Expand Down

0 comments on commit 4b7dec1

Please sign in to comment.