{"_id":"@apostrophecms/mongodb-snapshot","_rev":"4-c1bd07e250f3d1bfeab96822cae99635","name":"@apostrophecms/mongodb-snapshot","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@apostrophecms/mongodb-snapshot","version":"1.0.0","author":{"name":"Apostrophe Technologies"},"license":"MIT","_id":"@apostrophecms/mongodb-snapshot@1.0.0","maintainers":[{"name":"alexgilbert","email":"alex@apostrophecms.com"},{"name":"stuartromanek","email":"stuart@punkave.com"},{"name":"boutell","email":"tom@apostrophecms.com"},{"name":"etlaurent","email":"npm_etlaurent.cartoon369@passmail.net"},{"name":"valjed","email":"vjeudy@protonmail.com"},{"name":"romanek","email":"stuart+npm@apostrophecms.com"},{"name":"bodonkey","email":"robert@robertmeans.net"},{"name":"haroun","email":"haroun.npm@icloud.com"}],"homepage":"https://github.com/apostrophecms/mongodb-snapshot#readme","bugs":{"url":"https://github.com/apostrophecms/mongodb-snapshot/issues"},"bin":{"mongodb-snapshot-read":"bin/mongodb-snapshot-read","mongodb-snapshot-write":"bin/mongodb-snapshot-write"},"dist":{"shasum":"d5bfac452dec52892c84635f32200d7b473c46d5","tarball":"https://registry.npmjs.org/@apostrophecms/mongodb-snapshot/-/mongodb-snapshot-1.0.0.tgz","fileCount":8,"integrity":"sha512-Q8BhIhis33wGcW//HwCGoEUkwVIR4Y/bCrLT3aKHsBjzXXhRquAzbQJwZs6meW3sEu71UZZxIg95AcRhl/qzVA==","signatures":[{"sig":"MEUCIAmmmqVRjKIojWzKrnRWk4I8JC54VzD5yuJltgQS8M+BAiEAvnW9wclmudmLmyEOX2CSlQtpjw8q27ScY4ez1EvSMkA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":11504},"main":"index.js","gitHead":"dfda128b0058fcf8fa9e2854e9d322e53f7b61d8","scripts":{"test":"mocha"},"_npmUser":{"name":"boutell","email":"tom@apostrophecms.com"},"repository":{"url":"git+https://github.com/apostrophecms/mongodb-snapshot.git","type":"git"},"_npmVersion":"10.9.2","description":"Save and restore mongodb snapshots without mongodump and mongorestore","directories":{},"_nodeVersion":"18.20.4","dependencies":{"bson":"^6.10.1","boring":"^1.1.1","mongodb":"^6.12.0"},"_hasShrinkwrap":false,"devDependencies":{"mocha":"^11.0.1"},"_npmOperationalInternal":{"tmp":"tmp/mongodb-snapshot_1.0.0_1737556491296_0.8379677980823355","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@apostrophecms/mongodb-snapshot","version":"1.1.0","author":{"name":"Apostrophe Technologies"},"license":"MIT","_id":"@apostrophecms/mongodb-snapshot@1.1.0","maintainers":[{"name":"alexgilbert","email":"alex@apostrophecms.com"},{"name":"stuartromanek","email":"stuart@punkave.com"},{"name":"boutell","email":"tom@apostrophecms.com"},{"name":"etlaurent","email":"npm_etlaurent.cartoon369@passmail.net"},{"name":"valjed","email":"vjeudy@protonmail.com"},{"name":"romanek","email":"stuart+npm@apostrophecms.com"},{"name":"bodonkey","email":"robert@robertmeans.net"},{"name":"haroun","email":"haroun.npm@icloud.com"}],"homepage":"https://github.com/apostrophecms/mongodb-snapshot#readme","bugs":{"url":"https://github.com/apostrophecms/mongodb-snapshot/issues"},"bin":{"mongodb-snapshot-read":"bin/mongodb-snapshot-read","mongodb-snapshot-write":"bin/mongodb-snapshot-write"},"dist":{"shasum":"5a0facaaa744b9baf5266e0b43cc52733f5c4419","tarball":"https://registry.npmjs.org/@apostrophecms/mongodb-snapshot/-/mongodb-snapshot-1.1.0.tgz","fileCount":9,"integrity":"sha512-rFkBmbpBhNDLDCNyRmkC4bZolBz0SNXpJETaxBdc6zFoE01ygPRmtzpQulkMq5y4/rGDzCZq8k8gCL2hlpxZMA==","signatures":[{"sig":"MEYCIQDYjeIfnSW6n+NeSsA8QF9YouinVzwvA7EIEymz1PbwYQIhAOwyM8/KksdAVlcFj93P2aPnE0tatcknl1afXjILaFDK","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":14816},"main":"index.js","gitHead":"19a9e17819c4b9a7c4df9696435a409c18fd0ef3","scripts":{"test":"mocha"},"_npmUser":{"name":"boutell","email":"tom@apostrophecms.com"},"repository":{"url":"git+https://github.com/apostrophecms/mongodb-snapshot.git","type":"git"},"_npmVersion":"10.9.2","description":"Save and restore mongodb snapshots without mongodump and mongorestore","directories":{},"_nodeVersion":"18.20.4","dependencies":{"bson":"^6.10.1","boring":"^1.1.1","mongodb":"^6.12.0"},"_hasShrinkwrap":false,"devDependencies":{"mocha":"^11.0.1"},"_npmOperationalInternal":{"tmp":"tmp/mongodb-snapshot_1.1.0_1737569839178_0.7213866564442104","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2025-01-22T14:34:51.159Z","modified":"2026-01-26T19:09:12.991Z","1.0.0":"2025-01-22T14:34:51.474Z","1.1.0":"2025-01-22T18:17:19.397Z"},"bugs":{"url":"https://github.com/apostrophecms/mongodb-snapshot/issues"},"author":{"name":"Apostrophe Technologies"},"license":"MIT","homepage":"https://github.com/apostrophecms/mongodb-snapshot#readme","repository":{"url":"git+https://github.com/apostrophecms/mongodb-snapshot.git","type":"git"},"description":"Save and restore mongodb snapshots without mongodump and mongorestore","maintainers":[{"email":"alex@apostrophecms.com","name":"alexgilbert"},{"email":"tom@apostrophecms.com","name":"boutell"},{"email":"stuart+npm@apostrophecms.com","name":"romanek"},{"email":"robert.means1969+apostrophecms@gmail.com","name":"bodonkey"}],"readme":"# @apostrophecms/mongodb-snapshot\n\nA simple nodejs utility library to create and restore snapshots of mongodb databases without the need for `mongodump` and `mongorestore` to be installed. This reduces unnecessary dependencies on packages users may not be eager to install, especially developers relying solely on MongoDB Atlas for MongoDB hosting.\n\nBecause the format of mongodb archive files is a bit more complicated and apparently undocumented, and the BSON format has no readily available streaming support in JavaScript, this module **does not** read and write mongodump files. Instead it reads and writes a simple format based on EJSON (Extended JSON).\n\nAs a bonus, command line `mongodb-snapshot-write` and `mongodb-snapshot-read` utilities are provided. Of course these do not perform as quickly as `mongodump` and `mongorestore`.\n\n## Installation\n```bash\n# If you want to use the utilities\nnpm install -g @apostrophecms/mongodb-snapshot\n\n# If you want to use the library in your nodejs code\nnpm install @apostrophecms/mongodb-snapshot\n```\n\n## Command line usage\n\n```bash\nmongodb-snapshot-write --from=mongodb://localhost:27017/mydbname --to=myfile.snapshot\n# add --erase ONLY if you want the previous contents removed first!\nmongodb-snapshot-read --from=myfile.snapshot --to=mongodb://localhost:27017/mydbname --erase\n```\n\n### Including and excluding collections\n\nWith both commands, if you want to exclude certain certain collections, just add:\n\n```\n--exclude=name1,name2\n```\n\n### Filtering individual documents\n\nWith the `mongodb-snapshot-write` command **only**, you can specify a MongoDB query to\nfilter the documents for any collection. For example:\n\n```bash\nmongodb-snapshot-write --from=mongodb://localhost:27017/mydbname --to=myfile.snapshot --filter-COLLECTION-NAME-HERE='{\"type\":\"interesting\"}'\n```\n\nThe query must be valid JSON. Watch out for shell escaping rules (note the single quotes in the example). Note that\nMongoDB has a `$regex` operator which can be useful here.\n\nYou may specify filters for as many collections as you wish. Note that the parameter name begins with `--filter-` followed by the collection name.\n\n## Node.js API usage\n\n```javascript\n// Note: ESM import syntax also works.\n\n// writing\n\nconst { MongoClient } = require('mongodb');\nconst { write } = require('@apostrophecms/mongodb-snapshot');\n\nasync function saveASnapshot() {\n  const client = new MongoClient(yourMongodbUriGoesHere);\n  await client.connect();\n  const db = await client.db();\n  // Writes the contents of db to myfilename.snapshot, including indexes\n  // Two collections are excluded (optional third argument)\n  await write(db, 'myfilename.snapshot', {\n    // No password hashes please\n    exclude: [ 'aposUsersSafe' ],\n    filters: {\n      aposDocs: {\n        type: {\n          // No users please\n          $ne: '@apostrophecms/user'\n        }\n      }\n    }});\n}\n```\n\n```javascript\nconst { MongoClient } = require('mongodb');\nconst { erase, read } = require('@apostrophecms/mongodb-snapshot');\n\nasync function saveASnapshot() {\n  const client = new MongoClient(yourMongodbUriGoesHere);\n  await client.connect();\n  const db = await client.db();\n  // If you want to replace the current contents and avoid unique key errors and/or duplicate\n  // documents, call erase first\n  await erase(db);\n  // Two collections are excluded (optional third argument)\n  await read(db, 'myfilename.snapshot', { exclude: [ 'coll3', 'coll4' ]});\n}\n```\n\n## Limitations\n\nCorrectness comes before performance, for now. Sensible amounts of parallelism might help.\n\n## Credits\n\nThis module was [originally created for use with ApostropheCMS](https://apostrophecms.com), an open-source Node.js CMS with robust support for in-context, on-page editing, multitenant, multisite projects and lots of other great features worth checking out.\n","readmeFilename":"README.md"}