Socket
Book a DemoInstallSign in
Socket

mongodb_backup_tool

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb_backup_tool

Backup MongoDB database collections to JSON or CSV

latest
npmnpm
Version
1.0.3
Version published
Weekly downloads
7
-97.9%
Maintainers
1
Weekly downloads
 
Created
Source

MongoDB Backup Tool

npm license downloads

Backup all collections from any MongoDB database to JSON or CSV — with a single command.

A lightweight, zero-config CLI tool to export all collections from a MongoDB database into JSON or CSV files, organized in timestamped folders.

Perfect for:

  • Local development
  • Automated backups
  • Data migration
  • Analytics & reporting

🚀 Features

FeatureSupported
Export to JSON or CSV✅ Yes
Backup all collections✅ Yes
Skips system databases✅ Yes (admin, config, local)
Timestamped backup folders✅ Yes
Works with MongoDB Atlas✅ Yes
Global CLI (mongo-backup)✅ Yes
No config files needed✅ Yes

⚙️ Installation

npm install -g mongodb-backup-tool

Requirements

  • Node.js v14+
  • MongoDB 3.6+

💻 Usage

Basic Command

mongo-backup --uri <mongodb-uri> [options]

Options

FlagAliasDescriptionDefault
--uri-uRequired. MongoDB connection string
--format-fOutput format: json or csvjson
--output-oOutput directory for backups./backups

🧩 Examples

1️⃣ Backup to JSON (default)

mongo-backup -u "mongodb://localhost:27017/mydb" -f json

2️⃣ Backup to CSV

mongo-backup -u "mongodb://user:pass@host:27017/mydb" -f csv -o ./my-backups

3️⃣ Backup MongoDB Atlas Database

mongo-backup \
  -u "mongodb+srv://user:pass@cluster0.mongodb.net/myDatabase" \
  -f json \
  -o ./atlas-backup

4️⃣ Quick Local Dev Backup (One-liner)

mongo-backup -u mongodb://localhost:27017 -f csv

📁 Output Structure

backups/
└── backup-2025-10-28T14-30-22-123Z/
    ├── mydb/
    │   ├── users.json
    │   ├── products.csv
    │   └── orders.json
    └── analytics/
        └── events.csv
  • Each database → folder
  • Each collection → file (collection.json or collection.csv)

🧠 Programmatic Usage (Node.js)

You can also use it inside your Node.js apps:

const { backupDatabase } = require('mongodb-backup-tool');

backupDatabase(
  'mongodb://localhost:27017/mydb',
  './custom-backup',
  'csv'
)
  .then(() => console.log('Backup done!'))
  .catch(err => console.error('Failed:', err));

🔐 Security Tips

Never commit your MongoDB URI to Git.
Use environment variables instead:

export MONGODB_URI="mongodb+srv://user:pass@cluster0.mongodb.net/mydb"
mongo-backup -u $MONGODB_URI -f json

🧾 Supported MongoDB Versions

  • MongoDB 3.6+
  • MongoDB Atlas
  • Local, Docker, or Cloud (AWS, GCP, Azure)

🛠 Troubleshooting

IssueSolution
command not found: mongo-backupRun npm install -g mongodb-backup-tool again
Authentication failedDouble-check username/password in URI
Empty CSV filesCollection may be empty — normal behavior
Permission deniedRun terminal as admin or use a different output folder

🧑‍💻 Development & Contributing

Want to improve this tool?

git clone https://github.com/yourname/mongodb-backup-tool.git
cd mongodb-backup-tool
npm install
npm link  # test CLI locally

Scripts

"scripts": {
  "test": "node test.js"
}

🗺 Roadmap

  • Add .zip compression
  • Upload to S3 / GCS
  • Schedule with cron
  • Incremental backups
  • Web UI dashboard

📜 License

MIT © 2025 Your Name

👨‍💻 Author

Pratham – Feel free to reach out!
Star this repo if you found it useful!

Keywords

mongodb

FAQs

Package last updated on 28 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts