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

Add CodecOptions examples

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 3.7
    • Docs

    Description

      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
      

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: