sharedb-milestone-mongo is a database adapter for ShareDB that specifically targets MongoDB, enabling the use of 'milestone snapshots' to optimize the `connection.fetchSnapshot` method. These snapshots create specific points in time from which a smaller number of operations can be applied to reconstruct the requested document version, significantly improving performance for frequently accessed older versions. The current stable version is 2.1.0, and the package demonstrates a consistent release cadence, frequently updating to support newer versions of both Node.js (dropping older LTS versions) and its core dependencies, `mongodb` and `sharedb`. It stores these milestones in a dedicated `m_COLLECTION` in the MongoDB database, configurable for saving intervals or complex middleware-based logic.
npm install sharedb-milestone-mongoVerified import paths — ran on the pinned version, not inferred.
Initializes ShareDB with sharedb-milestone-mongo, connecting to a MongoDB instance. It demonstrates basic document fetching/creation using the configured milestone database.
Upgrade Node.js to v18 or a later supported version. Older Node.js versions require sharedb-milestone-mongo v1.x.
Upgrade Node.js to v16 or newer for versions >=1.0.0. For v1.0.0 specifically, v16+ is required; for v2.0.0+, v18+ is needed.
Review error handling logic and update to check for string error codes instead of direct object comparisons or older error patterns.
Ensure your `mongodb` package dependency is v3.x or higher. For full compatibility, refer to recent release notes for the specific `mongodb` version supported (e.g., v2.1.0 supports `mongodb@7`).
Always set `request.saveMilestoneSnapshot` to `false` if you intend to prevent milestone snapshots for a given request/collection, rather than leaving it undefined or null.
Plan index creation carefully, especially on production systems with substantial data. Consider creating indexes during maintenance windows or on smaller, new collections.
For CommonJS: `const MongoMilestoneDB = require('sharedb-milestone-mongo');`. For ES Modules: `import MongoMilestoneDB from 'sharedb-milestone-mongo';`.Check the `sharedb-milestone-mongo` release notes (e.g., on GitHub or npm) for the specific version you are using and update your `mongodb` dependency to a compatible version (e.g., v2.1.0 supports `mongodb@7`).
Upgrade your Node.js environment to the minimum required version for your `sharedb-milestone-mongo` version (e.g., v2.0.0 requires Node.js v18+).
Ensure your MongoDB server is running and accessible from the application's host, and verify the connection string (host, port, database name) is correct.