Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-2282

Support custom serialize / deserialize methods for collections

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON, Native
    • 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 Unassigned
            Reporter:
            daniel.aprahamian@mongodb.com Daniel Aprahamian (Inactive)
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: