{"id":28945341,"url":"https://github.com/apostrophecms/mongodb-snapshot","last_synced_at":"2026-02-09T22:31:53.802Z","repository":{"id":273624115,"uuid":"920285231","full_name":"apostrophecms/mongodb-snapshot","owner":"apostrophecms","description":"Save and restore mongodb snapshots without mongodump and mongorestore","archived":false,"fork":false,"pushed_at":"2025-01-22T18:17:18.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-19T09:46:19.501Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apostrophecms.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-21T22:03:03.000Z","updated_at":"2025-01-22T18:17:06.000Z","dependencies_parsed_at":"2025-01-22T02:22:47.859Z","dependency_job_id":"7a5ef770-47c7-442b-a956-e67326a55583","html_url":"https://github.com/apostrophecms/mongodb-snapshot","commit_stats":null,"previous_names":["apostrophecms/mongodb-snapshot"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/apostrophecms/mongodb-snapshot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apostrophecms%2Fmongodb-snapshot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apostrophecms%2Fmongodb-snapshot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apostrophecms%2Fmongodb-snapshot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apostrophecms%2Fmongodb-snapshot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apostrophecms","download_url":"https://codeload.github.com/apostrophecms/mongodb-snapshot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apostrophecms%2Fmongodb-snapshot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29283589,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-09T21:57:15.303Z","status":"ssl_error","status_checked_at":"2026-02-09T21:57:11.537Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-23T07:12:44.816Z","updated_at":"2026-02-09T22:31:53.795Z","avatar_url":"https://github.com/apostrophecms.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapostrophecms%2Fmongodb-snapshot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapostrophecms%2Fmongodb-snapshot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapostrophecms%2Fmongodb-snapshot/lists"}