y-mongodb-provider is a database adapter that enables persistent storage and retrieval of Yjs collaborative documents using MongoDB. It serves as a backend for y-websocket servers, allowing Yjs document states to be saved and loaded, thereby ensuring data durability across server restarts or disconnections. The current stable version is 0.2.1, with updates primarily focused on dependency management, internal driver improvements, and bug fixes, indicating an active development status though without a strict release cadence. Key differentiators include its specific integration with MongoDB (unlike Yjs's officially supported y-leveldb), its ability to handle Yjs updates exceeding MongoDB's 16MB document size limit (since v0.1.8), and its use of the official MongoDB Node.js Driver for enhanced security and performance. It's important to note that this package is not officially supported by the Yjs team.
npm install y-mongodb-providerVerified import paths — ran on the pinned version, not inferred.
This example sets up a Yjs WebSocket server using `y-websocket` and integrates `y-mongodb-provider` for persistent storage of Yjs document states in a MongoDB database. It demonstrates binding document state on connection and asynchronously storing updates as they occur.
Review the GitHub repository for active development, open issues, and pull requests to gauge maintenance status and potential issues. Consider contributing to its development if you find gaps.
Upgrade your Node.js environment to version 16 or later (e.g., `nvm install 16 && nvm use 16`).
Review the official MongoDB Node.js driver documentation for any specific connection string options or client configurations, especially if encountering unexpected behavior when migrating from versions prior to 0.1.8.
Manually instantiate `MongoClient`, connect it, and pass the `{ client, db: client.db('yourDatabaseName') }` object to the `MongodbPersistence` constructor.Ensure that if you intend to store all documents within a single, named collection, `multipleCollections` must be set to `false` (which is its default value).
Verify that the database name specified in your MongoDB connection string or through the `client.db('databaseName')` call accurately corresponds to the database against which your MongoDB user is authenticated and has the necessary permissions.