PHPackages                             yadavsourabhgh/mongo-keepalive - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. yadavsourabhgh/mongo-keepalive

ActiveLibrary[Database &amp; ORM](/categories/database)

yadavsourabhgh/mongo-keepalive
==============================

Keep MongoDB Atlas free-tier clusters alive by sending periodic ping commands

1.0.0(2mo ago)00MITHTMLPHP &gt;=8.1CI failing

Since Mar 4Pushed 2mo agoCompare

[ Source](https://github.com/YadavSourabhGH/mongo-keepalive)[ Packagist](https://packagist.org/packages/yadavsourabhgh/mongo-keepalive)[ Docs](https://github.com/YadavSourabhGH/mongo-keepalive)[ RSS](/packages/yadavsourabhgh-mongo-keepalive/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

mongo-keepalive
===============

[](#mongo-keepalive)

[![npm](https://camo.githubusercontent.com/29e13cb3113e210b0e65dee3cbd6ee84cdcbe1075a3e4bbbbd8e93769e7f7260/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f6d6f6e676f2d6b656570616c6976653f7374796c653d666c61742d737175617265266c6f676f3d6e706d266c6162656c3d6e706d)](https://www.npmjs.com/package/mongo-keepalive)[![PyPI](https://camo.githubusercontent.com/1cc80c07db57110c4620ac665b1b76cb52055a11d7eaf05107f768f904ae574b/68747470733a2f2f696d672e736869656c64732e696f2f707970692f762f6d6f6e676f2d6b656570616c6976653f7374796c653d666c61742d737175617265266c6f676f3d70797069266c6162656c3d50795049)](https://pypi.org/project/mongo-keepalive/)[![Crates.io](https://camo.githubusercontent.com/e9807d4ba1deacac340ad6750f83e4b2f80f6acb662914fc7c9413f579c58438/68747470733a2f2f696d672e736869656c64732e696f2f6372617465732f762f6d6f6e676f2d6b656570616c6976653f7374796c653d666c61742d737175617265266c6f676f3d72757374266c6162656c3d6372617465732e696f)](https://crates.io/crates/mongo-keepalive)[![NuGet](https://camo.githubusercontent.com/25cd30cfe314bf0d3dbdc417acf80d6fa8f646c880e1b090bf3b95471a254011/68747470733a2f2f696d672e736869656c64732e696f2f6e756765742f762f4d6f6e676f4b656570416c6976653f7374796c653d666c61742d737175617265266c6f676f3d6e75676574266c6162656c3d4e75476574)](https://www.nuget.org/packages/MongoKeepAlive)[![RubyGems](https://camo.githubusercontent.com/c42577c74926dcf8ae4c432e36d985e3e881cf3bcc8f90e31699dfd83ddc38b8/68747470733a2f2f696d672e736869656c64732e696f2f67656d2f762f6d6f6e676f2d6b656570616c6976653f7374796c653d666c61742d737175617265266c6f676f3d7275627967656d73266c6162656c3d67656d)](https://rubygems.org/gems/mongo-keepalive)[![pub.dev](https://camo.githubusercontent.com/2bfd1f5d8de51239da9f7ceaf712cc0269239aa8c7e6ec5f2174b20902e3eaeb/68747470733a2f2f696d672e736869656c64732e696f2f7075622f762f6d6f6e676f5f6b656570616c6976653f7374796c653d666c61742d737175617265266c6f676f3d64617274266c6162656c3d7075622e646576)](https://pub.dev/packages/mongo_keepalive)[![License: MIT](https://camo.githubusercontent.com/1b01ef0024ba0866c115986b895301f657c1b21fc29f05c4844b7f2e8d89204d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Prevent MongoDB Atlas free-tier clusters from becoming inactive by periodically sending a `ping` command.

MongoDB Atlas pauses free-tier (M0) clusters after **60 days of inactivity**. This library keeps your cluster alive by running `db.adminCommand({ ping: 1 })` on a configurable interval (default: every 12 hours).

---

Supported Languages
-------------------

[](#supported-languages)

LanguagePackageStatusDirectoryNode.js[`mongo-keepalive`](https://www.npmjs.com/package/mongo-keepalive)✅ Published`node/`Python[`mongo-keepalive`](https://pypi.org/project/mongo-keepalive/)✅ Published`python/`Go`mongo-keepalive/go`📦 Tag-based`go/`Rust[`mongo-keepalive`](https://crates.io/crates/mongo-keepalive)✅ Published`rust/`Java`mongo-keepalive`🚧 Ready`java/`PHP`mongo-keepalive`🚧 Ready`php/`Ruby[`mongo-keepalive`](https://rubygems.org/gems/mongo-keepalive)✅ Published`ruby/`C#[`MongoKeepAlive`](https://www.nuget.org/packages/MongoKeepAlive)✅ Published`csharp/`Dart[`mongo_keepalive`](https://pub.dev/packages/mongo_keepalive)✅ Published`dart/`Kotlin`mongo-keepalive`🚧 Ready`kotlin/`**Status Legend:**

- ✅ Published: Available on package registry
- 📦 Tag-based: Install via GitHub tag/module path
- 🚧 Ready: Code complete, publishing in progress

---

Why Use This?
-------------

[](#why-use-this)

- 🎯 **Simple**: One function call to keep your cluster alive
- 🔄 **Reliable**: Built-in retry logic handles transient failures
- ⚡ **Lightweight**: Minimal memory footprint and dependencies
- 🌍 **Multi-language**: Use the same solution across your entire stack
- 🔧 **Configurable**: Adjust ping intervals to your needs
- 📝 **Production-ready**: Comprehensive logging and error handling

---

Installation
------------

[](#installation)

### Node.js

[](#nodejs)

```
npm install mongo-keepalive
```

### Python

[](#python)

```
pip install mongo-keepalive
```

### Go

[](#go)

```
go get github.com/YadavSourabhGH/mongo-keepalive/go
```

### Rust

[](#rust)

```
[dependencies]
mongo-keepalive = "1.0.0"
```

### Java / Kotlin (Maven)

[](#java--kotlin-maven)

```

  com.mongokeepalive
  mongo-keepalive
  1.0.0

```

### PHP

[](#php)

```
composer require YadavSourabhGH/mongo-keepalive
```

### Ruby

[](#ruby)

```
gem install mongo-keepalive
```

### C#

[](#c)

```
dotnet add package MongoKeepAlive
```

### Dart

[](#dart)

```
dart pub add mongo_keepalive
```

---

Usage
-----

[](#usage)

Every implementation exposes a similar API:

```
startKeepAlive({
  uri: "mongodb+srv://user:pass@cluster.mongodb.net/db",
  interval: "12h"
})

```

### Node.js

[](#nodejs-1)

```
const { startKeepAlive } = require("mongo-keepalive");

startKeepAlive({
  uri: "mongodb+srv://user:pass@cluster.mongodb.net/db",
  interval: "12h",
});
```

### Python

[](#python-1)

```
from mongo_keepalive import start_keep_alive

start_keep_alive(
    uri="mongodb+srv://user:pass@cluster.mongodb.net/db",
    interval="12h",
)
```

### Go

[](#go-1)

```
package main

import keepalive "github.com/YadavSourabhGH/mongo-keepalive/go"

func main() {
    keepalive.StartKeepAlive(keepalive.Options{
        URI:      "mongodb+srv://user:pass@cluster.mongodb.net/db",
        Interval: "12h",
    })
}
```

### Rust

[](#rust-1)

```
use mongo_keepalive::start_keep_alive;

#[tokio::main]
async fn main() {
    start_keep_alive(
        "mongodb+srv://user:pass@cluster.mongodb.net/db",
        "12h",
    ).await;
}
```

### Java

[](#java)

```
import com.mongokeepalive.KeepAlive;

public class Main {
    public static void main(String[] args) {
        KeepAlive.startKeepAlive(
            "mongodb+srv://user:pass@cluster.mongodb.net/db",
            "12h"
        );
    }
}
```

### PHP

[](#php-1)

```
use MongoKeepAlive\KeepAlive;

KeepAlive::startKeepAlive(
    'mongodb+srv://user:pass@cluster.mongodb.net/db',
    '12h'
);
```

### Ruby

[](#ruby-1)

```
require "mongo_keepalive"

MongoKeepAlive.start_keep_alive(
  uri: "mongodb+srv://user:pass@cluster.mongodb.net/db",
  interval: "12h"
)
```

### C#

[](#c-1)

```
using MongoKeepAlive;

KeepAlive.StartKeepAlive(
    "mongodb+srv://user:pass@cluster.mongodb.net/db",
    "12h"
);
```

### Dart

[](#dart-1)

```
import 'package:mongo_keepalive/keepalive.dart';

void main() {
  startKeepAlive(
    uri: 'mongodb+srv://user:pass@cluster.mongodb.net/db',
    interval: '12h',
  );
}
```

### Kotlin

[](#kotlin)

```
import com.mongokeepalive.KeepAlive

fun main() {
    KeepAlive.startKeepAlive(
        uri = "mongodb+srv://user:pass@cluster.mongodb.net/db",
        interval = "12h"
    )
}
```

---

How It Works
------------

[](#how-it-works)

1. **Connects** to your MongoDB cluster using the official driver for each language.
2. **Pings** the database with `db.adminCommand({ ping: 1 })` at the configured interval.
3. **Retries** automatically on transient failures (3 attempts with 5-second delays).
4. **Logs** every ping attempt and result with timestamps.
5. **Runs efficiently** — uses a single lightweight timer/scheduler with minimal memory usage.

The ping command is a lightweight operation that doesn't impact your cluster's performance but successfully registers as "activity" to prevent automatic pausing.

---

Configuration
-------------

[](#configuration)

OptionTypeDefaultDescription`uri`string—MongoDB connection string (required)`interval`string`"12h"`Ping interval (e.g. `"6h"`, `"30m"`)### Interval Format

[](#interval-format)

- `"30m"` → 30 minutes
- `"6h"` → 6 hours
- `"12h"` → 12 hours (default)

---

Contributing
------------

[](#contributing)

Contributions are welcome! Please follow these steps:

1. Fork the repository.
2. Create a feature branch: `git checkout -b feat/my-feature`.
3. Commit your changes: `git commit -m "feat: add my feature"`.
4. Push to the branch: `git push origin feat/my-feature`.
5. Open a Pull Request.

Please ensure your code:

- Follows the idiomatic conventions of the target language.
- Includes logging and retry logic.
- Does not introduce unnecessary dependencies.

---

Features
--------

[](#features)

✨ **Cross-platform compatibility**: Works across all major programming languages and ecosystems
🔐 **Secure**: Uses official MongoDB drivers with standard connection strings
⏱️ **Flexible intervals**: Configure from minutes to hours based on your needs
🛡️ **Error resilient**: Automatic retry logic with exponential backoff
📊 **Observable**: Built-in logging for monitoring and debugging
🚀 **Zero-config defaults**: Works out of the box with sensible 12-hour interval
♻️ **Graceful shutdown**: Clean stop mechanisms in all implementations
🎨 **Idiomatic code**: Each language implementation follows best practices and conventions

---

FAQ
---

[](#faq)

**Q: Will this increase my MongoDB Atlas costs?**
A: No. The ping command is extremely lightweight and doesn't count against your storage or compute quotas. Free-tier clusters remain free.

**Q: How often should I ping?**
A: The default 12-hour interval is recommended. This is frequent enough to prevent inactivity while minimizing unnecessary operations.

**Q: Can I use this in production?**
A: Yes! All implementations include proper error handling, logging, and retry logic suitable for production use.

**Q: Does this work with paid MongoDB Atlas tiers?**
A: Yes, but it's primarily designed for free-tier (M0) clusters which auto-pause after 60 days of inactivity.

**Q: What happens if my internet connection drops?**
A: The library will retry failed pings automatically and continue when connectivity is restored.

---

Links
-----

[](#links)

- 📦 [GitHub Repository](https://github.com/YadavSourabhGH/mongo-keepalive)
- 📝 [Publishing Guide](PUBLISHING.md)
- 🐛 [Report Issues](https://github.com/YadavSourabhGH/mongo-keepalive/issues)
- 💡 [Request Features](https://github.com/YadavSourabhGH/mongo-keepalive/issues)

---

License
-------

[](#license)

This project is licensed under the [MIT License](LICENSE).

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance86

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

70d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/47997d9dfd68b8f90cfc41ced99948b21eb4c72662648388cbf2d20c4caf7446?d=identicon)[yadavsourabh](/maintainers/yadavsourabh)

---

Tags

automationdatabasemongodbmaintenanceatlaspingclusterkeepalivefree-tierm0

### Embed Badge

![Health badge](/badges/yadavsourabhgh-mongo-keepalive/health.svg)

```
[![Health](https://phpackages.com/badges/yadavsourabhgh-mongo-keepalive/health.svg)](https://phpackages.com/packages/yadavsourabhgh-mongo-keepalive)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[alcaeus/mongo-php-adapter

Adapter to provide ext-mongo interface on top of mongo-php-library

46412.3M73](/packages/alcaeus-mongo-php-adapter)[moloquent/moloquent

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

120114.6k7](/packages/moloquent-moloquent)[facile-it/mongodb-bundle

Bundle service integration of official \[mongodb/mongo-php-library\](https://github.com/mongodb/mongo-php-library) driver library

38212.1k1](/packages/facile-it-mongodb-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
