Add CodecOptions examples

XMLWordPrintableJSON

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

      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 Hackett
              Reporter:
              Shane Harvey
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: