Support data validations classes (dataclass, pydantic, custom class, ...) as document_class

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Python Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Hi
      I'm working on a Python framework([Panther|https://github.com/alirn76/panther)] which wants to work natively with MongoDB, and I'm using Pymongo for this purpose.

      Now I want to add Pydantic BaseModel as a document_class but the document_class should be a subclass of MutableMapping, we can make it a subclass of dict by inheriting the MutableMapping and adding the necessary methods to it, but it won't work currently when we send it fields one by one (all fields should have a default value to work correctly)

      I have changed some code to make it possible to work with pydantic, but what is your opinion about this work? Should I work on it? Do you want to support more classes (dataclasses or something)

      Here are the changes I've made:

      https://github.com/AliRn76/mongo-python-driver/commit/6c26739eea6a0adf786cdb7336f259a64a6c3606 https://github.com/AliRn76/mongo-python-driver/commit/6c26739eea6a0adf786cdb7336f259a64a6c3606

      Kind regards,
      Ali RajabNezhad

              Assignee:
              Jib Adegunloye
              Reporter:
              Ali RajabNezhad
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated: