Registry / database / sharedb-milestone-mongo

sharedb-milestone-mongo

JSON →
library2.1.0jsnpmunverified

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-mongo
INSTALL
IMPORT
SIG · SHAREDB-MILESTONE-
S
sharedb-milestone-mongo
databasejavascriptv2.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MongoMilestoneDB
import MongoMilestoneDB from 'sharedb-milestone-mongo'; // or for CJS: const MongoMilestoneDB = require('sharedb-milestone-mongo');
import { MongoMilestoneDB } from 'sharedb-milestone-mongo';
The primary class is a default export, though the `require` syntax might imply a named export if one is not careful. Ensure correct default import for ESM.
ShareDB
import ShareDB from 'sharedb'; // or for CJS: const ShareDB = require('sharedb');
While not part of sharedb-milestone-mongo, ShareDB is always used in conjunction with this adapter and is typically imported as a default export.
MongoClient
import { MongoClient } from 'mongodb';
import mongodb from 'mongodb'; const MongoClient = mongodb.MongoClient;
When providing a custom MongoClient instance, it's crucial to correctly import named exports from the `mongodb` package.

Initializes ShareDB with sharedb-milestone-mongo, connecting to a MongoDB instance. It demonstrates basic document fetching/creation using the configured milestone database.

import ShareDB from 'sharedb'; import MongoMilestoneDB from 'sharedb-milestone-mongo'; const mongoUrl = process.env.MONGO_URL ?? 'mongodb://localhost:27017/test'; async function startServer() { try { const milestoneDb = new MongoMilestoneDB(mongoUrl); const shareDb = new ShareDB({ milestoneDb: milestoneDb }); // Example of using ShareDB with the milestone adapter const connection = shareDb.connect(); const doc = connection.get('mycollection', 'mydocument'); await new Promise((resolve, reject) => { doc.fetch(err => { if (err) return reject(err); if (doc.type === null) { doc.create({ content: 'Hello initial world!' }, resolve); } else { resolve(); } }); }); console.log('ShareDB with milestone-mongo initialized and document fetched/created.'); // Cleanup (in a real app, this would be part of graceful shutdown) // await milestoneDb.close(); // Note: MongoMilestoneDB doesn't expose a direct close method, it relies on underlying MongoClient close. // shareDb.close(); } catch (error) { console.error('Failed to start ShareDB server:', error); process.exit(1); } } startServer();
Debug
Known issues
breakingNode.js v16 support was dropped in v2.0.0. Ensure your environment uses Node.js v18 or newer.
fix
Upgrade Node.js to v18 or a later supported version. Older Node.js versions require sharedb-milestone-mongo v1.x.
affects: >=2.0.0
breakingNode.js v14 support was dropped in v1.0.0. This aligns with Node.js LTS lifecycle.
fix
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.
affects: >=1.0.0
breakingError handling was refactored in v1.0.0 to use string error codes and a dedicated error module. Direct comparison of error objects or properties might break.
fix
Review error handling logic and update to check for string error codes instead of direct object comparisons or older error patterns.
affects: >=1.0.0
breakingSupport for `mongodb@2` was explicitly dropped in v0.10.0. This means older MongoDB server versions or driver clients are no longer compatible.
fix
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`).
affects: >=0.10.0
gotchaWhen configuring complex milestone saving logic via ShareDB middleware, explicitly set `request.saveMilestoneSnapshot = false` to disable milestones for certain collections. Leaving it `null` will revert to the default interval logic.
fix
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.
affects: >=0.1.0
gotchaEnabling indexing on existing, large milestone collections can have a significant adverse impact on performance during the index creation process.
fix
Plan index creation carefully, especially on production systems with substantial data. Consider creating indexes during maintenance windows or on smaller, new collections.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: MongoMilestoneDB is not a constructor
Attempting to use `new MongoMilestoneDB()` with an incorrect import statement, likely trying to destructure a default export.
fix
For CommonJS: `const MongoMilestoneDB = require('sharedb-milestone-mongo');`. For ES Modules: `import MongoMilestoneDB from 'sharedb-milestone-mongo';`.
Error: Mongo driver version 'X' is not supported. Please use a supported version.
Mismatched `mongodb` package version with the `sharedb-milestone-mongo` version. The library has frequent updates to support new `mongodb` versions and drops support for older ones.
fix
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`).
Error: Node.js version X is not supported by sharedb-milestone-mongo Y. Please upgrade Node.js.
Running `sharedb-milestone-mongo` on an unsupported Node.js version. Newer versions of the library frequently drop support for older Node.js LTS releases.
fix
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+).
MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
The MongoDB server is not running or is inaccessible at the specified connection string.
fix
Ensure your MongoDB server is running and accessible from the application's host, and verify the connection string (host, port, database name) is correct.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
sharedbrequiredCore operational transformation library that this package extends and integrates with.
mongodbrequiredThe underlying MongoDB driver used for all database interactions.
Agent activity
18 hits · last 30 days
node
16
Meta
1
Resources
sharedb-milestone-mongo — npm install sharedb-milestone-mongo · libregistry