How to use sharedb-mongo - 2 common examples

To help you get started, we’ve selected a few sharedb-mongo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chili-epfl / collab-react-components / src / server / CollabServer.js View on Github external
CollabServer.start = (app = {}, options = {}) => {
  // We merge the options defined by the user
  CollabServer.options = {
    ...defaultOptions,
    ...options,
  };

  const server = http.createServer(app);
  let db = null;
  if (CollabServer.options.db.type === 'mongo') {
    db = CollabServer.options.db.url
      ? ShareDBMongo(CollabServer.options.db.url)
      : {};
    console.log('CollabServer: Using MongoDB adapter');
  } else {
    console.log(
      'CollabServer: No Database specified, falling back to In Memory'
    );
  }

  // Create the ShareDB backend (that will need to be exported)
  ShareDB.types.register(RichText.type);
  CollabServer.backend = new ShareDB({ db });

  // Create the Websocket server
  new WebSocket.Server({ server }).on('connection', function(ws) {
    CollabServer.backend.listen(new WebsocketJSONStream(ws));
    console.log('New socket client on CollabServer instance');
github dmapper / react-sharedb / test / _server / init.js View on Github external
exec(`mongo ${MONGO_DB} --eval "db.dropDatabase();"`, () => {
      mongo = shareDbMongo(MONGO_URL, { allowAllQueries: true })
      backend = racer.createBackend({ db: mongo })
      resolve()
    })
  })

sharedb-mongo

MongoDB database adapter for ShareDB

MIT
Latest version published 6 months ago

Package Health Score

67 / 100
Full package analysis

Popular sharedb-mongo functions