Ability to define transformer / mapper on the collection level.

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Won't Do
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON, Native
    • Not Needed
    • None
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Summary: It'd be nice to add way to create a collection instance and automatically call map/transform any time a document gets pulled from the database.  This would make it easy for mapping libraries (https://github.com/j/type-mongo-mapper) to be used without having to create a wrapper around the collection.

       

      Note: I know there's cursor.map and "extending cursors".  But just a simple:

       

      const mappedCollection = db.collection('users', { map: createUserDocumentMapper() });

      mappedCollection.find*() // every document will be put through the map function

       

      Please see the link below with examples:

      https://github.com/mongodb-js/mongodb-core/issues/301#issuecomment-384773766

              Assignee:
              Unassigned
              Reporter:
              Jordan Stout
              None
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: