sharedb-mongo is a database adapter for ShareDB, a full-stack library for realtime JSON document collaboration. It serves as both a snapshot store and an oplog for ShareDB documents, integrating directly with MongoDB. Currently at v5.1.0, the package sees active development with regular updates to support the latest Node.js and MongoDB versions. A key differentiator is its ability to unwrap JSON document snapshots, allowing direct MongoDB queries against these documents (for read-only operations), while strictly requiring ShareDB for any modifications to ensure proper operational transformation and persistence. It also extends MongoDB's querying capabilities within the ShareDB context through special `$`-prefixed operators for methods like `mapReduce` and `sort`.
npm install sharedb-mongoVerified import paths — ran on the pinned version, not inferred.
Initializes a ShareDB backend with sharedb-mongo as the database adapter and sets up a basic WebSocket server for client connections.
Upgrade your Node.js runtime to version 18 or higher.
Upgrade your Node.js runtime to version 16 or higher for sharedb-mongo v4.x, or 18+ for v5.x.
Ensure your `mongodb` package is version 3.x or higher, and your MongoDB server is compatible.
Always use the ShareDB API to make changes to documents managed by ShareDB. Only read-only operations are safe outside of ShareDB's control.
To disable: `new ShareDbMongo(mongoUrl, { disableIndexCreation: { src_seq_v: true } });`. Manually delete existing indexes if no longer needed.Upgrade to `sharedb-mongo@4.1.1` or later, which includes a fix for this issue. Avoid using `$map` in earlier versions.
Upgrade to `sharedb-mongo@4.1.1` or later, which resolved this memory leak.
If using CommonJS, `require('sharedb-mongo')` returns a function; call it with `const db = require('sharedb-mongo')(url);`. If using ESM, ensure `import ShareDbMongo from 'sharedb-mongo';` and then `new ShareDbMongo(url);`.