Plugin for the MongoDB Node.js driver that enables automatic serialization of Moment.js objects to Date objects when saving to MongoDB, and deserialization when retrieving. Current version 1.0.2 is stable, with no updates since 2017. It mutates the global Moment prototype to add a custom `toBSON` method, making it transparent to use. Compared to alternatives like `moment-mongoose` or manual transformation, this package integrates directly with the driver's serialization cycle.
npm install mongodb-momentNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to register mongodb-moment and save/load a Moment.js object as a Date in MongoDB.
Use isolated Moment instances or serialize manually to avoid prototype pollution.
Ensure you use async/await or Promise-based connection; mongo driver v3+ requires this.
Use dynamic import or switch to CommonJS. Alternatively, apply serialization manually.
Create a .d.ts file declaring module augmentation for Moment.
Test with your MongoDB driver version; consider alternatives like manual serialization.
Ensure you call require('mongodb-moment')(moment) before using moment objects with MongoDB.Use require() instead of import, or place the code in a CommonJS file.
Downgrade MongoDB driver to version 3.x or handle serialization manually.