{"library":"sharedb-milestone-mongo","title":"ShareDB Milestone MongoDB Adapter","description":"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.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install sharedb-milestone-mongo"],"cli":null},"imports":["import MongoMilestoneDB from 'sharedb-milestone-mongo';\n// or for CJS:\nconst MongoMilestoneDB = require('sharedb-milestone-mongo');","import ShareDB from 'sharedb';\n// or for CJS:\nconst ShareDB = require('sharedb');","import { MongoClient } from 'mongodb';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import ShareDB from 'sharedb';\nimport MongoMilestoneDB from 'sharedb-milestone-mongo';\n\nconst mongoUrl = process.env.MONGO_URL ?? 'mongodb://localhost:27017/test';\n\nasync function startServer() {\n  try {\n    const milestoneDb = new MongoMilestoneDB(mongoUrl);\n    const shareDb = new ShareDB({ milestoneDb: milestoneDb });\n\n    // Example of using ShareDB with the milestone adapter\n    const connection = shareDb.connect();\n    const doc = connection.get('mycollection', 'mydocument');\n\n    await new Promise((resolve, reject) => {\n      doc.fetch(err => {\n        if (err) return reject(err);\n        if (doc.type === null) {\n          doc.create({ content: 'Hello initial world!' }, resolve);\n        } else {\n          resolve();\n        }\n      });\n    });\n\n    console.log('ShareDB with milestone-mongo initialized and document fetched/created.');\n\n    // Cleanup (in a real app, this would be part of graceful shutdown)\n    // await milestoneDb.close(); // Note: MongoMilestoneDB doesn't expose a direct close method, it relies on underlying MongoClient close.\n    // shareDb.close();\n\n  } catch (error) {\n    console.error('Failed to start ShareDB server:', error);\n    process.exit(1);\n  }\n}\n\nstartServer();","lang":"typescript","description":"Initializes ShareDB with sharedb-milestone-mongo, connecting to a MongoDB instance. It demonstrates basic document fetching/creation using the configured milestone database.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}