Support custom serialize / deserialize methods for collections

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON, Native
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Prior art / related issues:

      The idea would be to support ODM-lite features in the driver at the collection level. It would apply transform hooks for any CRUD operation. This would help with integrations with full ODMs, and also allow users to use these features without an ODM for basic cases.

      One proposed syntax from this issue

      class Author {
        name: string;
      }
      
      class Article {
        _id: ObjectId;
        content: string;
        author: Author;
      }
      
      const collection = db.collection('articles', {
        transform: (doc: any) => {
          return Object.assign(new Article(), {
            ...doc,
            author: doc.author ? Object.assign(new Author(), { doc.author }) : undefined
          });
        }
      });
      

            Assignee:
            Unassigned
            Reporter:
            Daniel Aprahamian (Inactive)
            None
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: