mongo-pinger
v1.0.4
Published
A simple CLI to keep MongoDB Atlas clusters alive by pinging them
Maintainers
Readme
mongo-pinger
Keep your MongoDB Atlas free-tier clusters alive with automated scheduled pings.
MongoDB Atlas pauses inactive free-tier clusters. This CLI tool prevents that by pinging your database on a schedule via GitHub Actions, completely hands-off after a 30-second setup.
🎯 Why Use This?
- 🆓 Free tier stays active - No more "cluster paused" surprises
- ⚡ 30-second setup - One command, fully automated
- 🤖 GitHub Actions - Runs automatically, no server needed
- 🎨 Flexible scheduling - Weekly, monthly, or custom cron
- 🔒 Secure - Uses GitHub Secrets for credentials
🚀 Quick Start
One-Command Setup
npx mongo-pinger setupThat's it! The interactive wizard will:
- Ask for your preferred schedule (weekly/monthly/custom)
- Let you pick the day and time
- Generate a GitHub Actions workflow
- Optionally commit and push to git
- Show you exactly what to do next
What You Get
After setup, you'll have:
your-repo/
└── .github/
└── workflows/
└── ping.yml # Auto-generated, ready to use📖 Configuration
1. Add Your MongoDB URI as a Secret
The only manual step:
- Go to your GitHub repo
- Settings → Secrets and variables → Actions
- Click "New repository secret"
- Name:
DATABASE_URI - Value: Your MongoDB connection string
mongodb+srv://username:[email protected]/database
2. Push the Workflow (if not done automatically)
git add .github/workflows/ping.yml
git commit -m "Add MongoDB pinger workflow"
git push3. Test It!
- Go to the Actions tab in your GitHub repo
- Click "MongoDB Pinger"
- Click "Run workflow" to test manually
- ✅ You should see "MongoDB ping successful"
⚙️ Scheduling Options
The setup wizard supports three modes:
Weekly (Recommended)
Pick any day of the week. Perfect for free-tier clusters.
Example: Every Sunday at midnight UTC
Cron: 0 0 * * 0Monthly
Pick a day of the month (1-31). Great for low-traffic apps.
Example: 1st of every month at midnight UTC
Cron: 0 0 1 * *⚡ Custom
Enter any valid cron expression for advanced scheduling.
Examples:
0 */12 * * *- Every 12 hours0 0 * * 1-5- Weekdays only at midnight*/30 * * * *- Every 30 minutes (overkill!)
Use crontab.guru to build custom expressions.
Testing Locally
Test your MongoDB connection before pushing:
# With environment variable
DATABASE_URI='mongodb+srv://user:[email protected]/db' npx mongo-pinger
# Or create a .env file
echo "DATABASE_URI=your_connection_string" > .env
npx mongo-pingerExpected output:
✅ MongoDB ping successful🔧 How It Works
- GitHub Actions triggers on schedule (or manually)
- Installs
mongo-pingerfrom npm - Connects to your MongoDB cluster using
mongoose - Pings the database with
db.admin().ping() - Logs success or failure
- Disconnects cleanly
The ping is lightweight—just verifies the connection. No data is modified.
📊 Monitoring
View Execution History
- Go to your repo's Actions tab
- Click "MongoDB Pinger" workflow
- See all past runs with timestamps and results
Enable Notifications
Settings → Notifications → GitHub Actions
- Get emails when pings fail
- Stay informed without checking manually
Check Next Run
The setup wizard shows you when the next ping will happen in UTC time.
🛠️ Advanced Usage
Update Schedule
Just run setup again:
npx mongo-pinger setupChoose "Yes" when asked to overwrite the existing workflow.
Manual Trigger
Besides the schedule, you can always run manually:
- GitHub Actions tab → MongoDB Pinger → Run workflow
Multiple Databases
Create separate workflows for each database:
# Rename the workflow in .github/workflows/
ping-production.yml # Uses DATABASE_URI_PROD
ping-staging.yml # Uses DATABASE_URI_STAGINGThen add multiple secrets with different names.
🐛 Troubleshooting
"DATABASE_URI not configured"
- ✅ Check the secret name is exactly
DATABASE_URI(case-sensitive) - ✅ Verify you added it in Settings → Secrets → Actions
- ✅ Make sure you're on the default branch (
mainormaster)
"MongoDB ping failed: connection timeout"
- ✅ Test connection locally first:
DATABASE_URI='...' npx mongo-pinger - ✅ Verify your connection string is correct
- ✅ Check MongoDB Atlas Network Access:
- Add
0.0.0.0/0to whitelist GitHub Actions IPs - Or enable "Allow access from anywhere"
- Add
Workflow doesn't run on schedule
- ⏰ GitHub Actions can delay 5-15 minutes during high load
- 📅 First scheduled run may not happen immediately after setup
- 💤 Repos inactive for 60+ days have schedules disabled
- Fix: Make a commit to re-enable
"Module not found" errors
- 🔄 The new version uses
npx mongo-pinger@latest(no build needed) - 📦 If using an old workflow, run
npx mongo-pinger setupagain
🤝 Contributing
Contributions are welcome! Here's how:
- Fork the repo
- Create a feature branch:
git checkout -b feature/amazing - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing - Open a Pull Request
Development Setup
# Clone and install
git clone https://github.com/lankyjo/mongo-pinger.git
cd mongo-pinger
npm install
# Build TypeScript
npm run build
# Run locally
npm start
# Run setup wizard
npm run setup📄 License
MIT © Ikeji Joshua
🙏 Acknowledgments
- Built with Mongoose for MongoDB connectivity
- Powered by GitHub Actions
- Interactive prompts via Inquirer.js
📧 Support
Made with ❤️ to keep your MongoDB Atlas clusters alive
