{"_id":"@apostrophecms/mongodb-snapshot-stable","name":"@apostrophecms/mongodb-snapshot-stable","dist-tags":{"latest":"1.1.0"},"versions":{"1.1.0":{"name":"@apostrophecms/mongodb-snapshot-stable","version":"1.1.0","description":"Save and restore mongodb snapshots without mongodump and mongorestore","main":"index.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git+https://github.com/apostrophecms/apostrophe.git","directory":"packages/mongodb-snapshot"},"homepage":"https://github.com/apostrophecms/apostrophe/tree/main/packages/mongodb-snapshot#readme","author":{"name":"Apostrophe Technologies"},"license":"MIT","bugs":{"url":"https://github.com/apostrophecms/mongodb-snapshot/issues"},"dependencies":{"boring":"npm:@apostrophecms/boring-stable@^1.1.1","bson":"^6.10.1","mongodb":"^6.12.0"},"devDependencies":{"mocha":"^11.7.5"},"bin":{"mongodb-snapshot-write":"bin/mongodb-snapshot-write","mongodb-snapshot-read":"bin/mongodb-snapshot-read"},"gitHead":"b3e29f004f514041e1e389293ae67017c60d006e","_id":"@apostrophecms/mongodb-snapshot-stable@1.1.0","_nodeVersion":"24.10.0","_npmVersion":"11.6.1","dist":{"integrity":"sha512-te29paBNFraFAe+Qg5nFinBAn8aT38dWdPcZZqVhcm5p2R9KA4bnjBJe+OOIlM+qEB5WW+X9leCiSzsHohFoOw==","shasum":"4dd186eae130eebc144b755cff10bf01d05ffab7","tarball":"https://registry.npmjs.org/@apostrophecms/mongodb-snapshot-stable/-/mongodb-snapshot-stable-1.1.0.tgz","fileCount":9,"unpackedSize":14922,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCjMBzbz8SH5yFK3MuFUmMDAkjkzpw0/bhyu357YPWojgIhAKtdokb9d1jb7K7GCC6l2yeL61SrN+VdGCC1F7ZqbQ24"}]},"_npmUser":{"name":"boutell","email":"tom@apostrophecms.com"},"directories":{},"maintainers":[{"name":"alexgilbert","email":"alex@apostrophecms.com"},{"name":"boutell","email":"tom@apostrophecms.com"},{"name":"romanek","email":"stuart+npm@apostrophecms.com"},{"name":"bodonkey","email":"robert.means1969+apostrophecms@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/mongodb-snapshot-stable_1.1.0_1781112803181_0.9770810061789832"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-10T17:33:23.038Z","1.1.0":"2026-06-10T17:33:23.320Z","modified":"2026-06-10T17:33:23.600Z"},"maintainers":[{"name":"alexgilbert","email":"alex@apostrophecms.com"},{"name":"boutell","email":"tom@apostrophecms.com"},{"name":"romanek","email":"stuart+npm@apostrophecms.com"},{"name":"bodonkey","email":"robert.means1969+apostrophecms@gmail.com"}],"description":"Save and restore mongodb snapshots without mongodump and mongorestore","homepage":"https://github.com/apostrophecms/apostrophe/tree/main/packages/mongodb-snapshot#readme","repository":{"type":"git","url":"git+https://github.com/apostrophecms/apostrophe.git","directory":"packages/mongodb-snapshot"},"author":{"name":"Apostrophe Technologies"},"bugs":{"url":"https://github.com/apostrophecms/mongodb-snapshot/issues"},"license":"MIT","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","_rev":"1-c0b0d824dfc799add1960e67d77defcd"}