Yjs
Mongodb database adapter forPersistent Mongodb storage for y-websocket server
Notes:
- It is a fork of Y-leveldb
- is not official.
- Still under progress.
Use it
npm install y-mongodb --save
create a simple server
const http = ;const WebSocket = ;const Y = ;const MongodbPersistence = ;const utils = ; const location = processenvMONGODB_URI;const collection = 'yjs-transactions';const ldb = location collection; const production = processenvPRODUCTION != null;const port = processenvPORT || 8080; const server = http; // const wss = new WebSocket.Server({ server });const wss = noServer: true ; wss;server; /* Persistence must have the following signature:{ bindState: function(string,WSSharedDoc):void, writeState:function(string,WSSharedDoc):Promise }*/utils server; console
API
persistence = MongodbPersistence(mongoUril, collection)
Create a mongo persistence instance.
persistence.getYDoc(docName: string): Promise<Y.Doc>
Create a Y.Doc instance with the data stored in mongodb.
persistence.storeUpdate(docName: string, update: Uint8Array): Promise
Store a transaction to the database.
persistence.clearDocument(docName: string): Promise
Delete a document, and all associated data from the database.