-
Type: New Feature
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
None
Prior art / related issues:
- https://github.com/mongodb/node-mongodb-native/pull/1698
- https://github.com/mongodb/node-mongodb-native/pull/1755
- https://github.com/mongodb-js/mongodb-core/issues/454
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 }); } });