Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-1506

Add CodecOptions examples

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.7
    • Affects Version/s: None
    • Component/s: Docs

      We should add more documentation on how to use CodecOptions. For example, it's very simple to configure pymongo to return dictionaries that also support convenient attribute access:

      from pymongo import MongoClient
      
      class AttributeDict(dict):
          """A dict that supports attribute access."""
          def __getattr__(self, key):
              return self[key]
      
          def __setattr__(self, key, value):
              self[key] = value
      
      client = MongoClient(document_class=AttributeDict)
      client.test.test.insert_one({'field': {'nested': {'field': 1}}})
      doc = client.test.test.find_one({})
      assert doc.field.nested.field == 1
      

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: