home / skills / shipshitdev / library / mongodb-atlas-checker

This skill validates MongoDB Atlas setup for backend apps by checking connection strings, environment variables, and proper configuration patterns.

npx playbooks add skill shipshitdev/library --skill mongodb-atlas-checker

Review the files below or copy the command above to add this skill to your agents.

Files (3)
SKILL.md
2.2 KB
---
name: mongodb-atlas-checker
description: Verify MongoDB Atlas setup and configuration for backend applications. Checks connection strings, environment variables, connection pooling, and ensures proper setup for Next.js and NestJS applications.
version: 1.0.0
tags:
  - mongodb
  - atlas
  - database
  - backend
  - nestjs
  - nextjs
---

# MongoDB Atlas Checker

Verify MongoDB Atlas setup and configuration. Identifies configuration issues, missing environment variables, incorrect connection strings, and ensures proper database setup.

## When to Use

- Verifying MongoDB Atlas backend setup
- Checking connection string configuration
- Validating environment variable setup
- Troubleshooting database connection issues
- Auditing database setup before deployment

## Quick Checklist

### 1. Environment Variables

- [ ] `MONGODB_URI` exists (not hardcoded)
- [ ] Uses `mongodb+srv://` protocol (required for Atlas)
- [ ] Includes database name
- [ ] Includes `retryWrites=true&w=majority`
- [ ] No credentials in `.env.example`

### 2. Connection String Format

```
mongodb+srv://<username>:<password>@<cluster-host>/<database>?retryWrites=true&w=majority
```

### 3. Driver Installation

- [ ] `mongoose` or `mongodb` package installed
- [ ] In dependencies (not devDependencies)

### 4. Connection Setup

- [ ] Singleton pattern (Next.js)
- [ ] `MongooseModule.forRoot()` (NestJS)
- [ ] Error handling implemented

### 5. Atlas Configuration

- [ ] IP whitelist configured
- [ ] Database user exists with permissions
- [ ] SSL/TLS enabled (default with `mongodb+srv://`)

## Common Issues

| Issue | Solution |
|-------|----------|
| Missing `MONGODB_URI` | Add to `.env.local` or `.env` |
| Wrong protocol | Use `mongodb+srv://` not `mongodb://` |
| Multiple connections (Next.js) | Use singleton pattern |
| Connection timeout | Check IP whitelist in Atlas |
| Auth failed | Verify credentials, URL-encode special chars |

## Recommended Connection Options

```typescript
{
  retryWrites: true,
  w: 'majority',
  maxPoolSize: 10,
  serverSelectionTimeoutMS: 5000,
  bufferCommands: false,
}
```

---

**For detailed setup patterns, verification scripts, and complete examples:** `references/full-guide.md`

Overview

This skill verifies MongoDB Atlas setup and configuration for backend applications. It inspects connection strings, environment variables, driver usage, and framework-specific connection patterns to surface misconfigurations. It helps ensure reliable connections for Next.js and NestJS apps before deployment.

How this skill works

The checker parses environment files and source code to confirm MONGODB_URI exists, follows the mongodb+srv:// format, and includes required options like retryWrites and w=majority. It looks for proper driver installation and dependency placement, validates singleton or framework-specific connection patterns (e.g., Next.js singleton, MongooseModule.forRoot in NestJS), and flags common pitfalls like credentials in example files or missing IP whitelist entries. The tool reports actionable issues and recommends connection options and fixes.

When to use it

  • Before deploying a backend that uses MongoDB Atlas to catch configuration errors early
  • When troubleshooting intermittent connection timeouts or authentication failures
  • During code review to ensure environment variables and connection strings are secure
  • When migrating projects to Next.js or NestJS to validate recommended connection patterns
  • As part of an audit to confirm Atlas network and user settings are correct

Best practices

  • Keep MONGODB_URI in environment variables, not hardcoded in source or examples
  • Use mongodb+srv:// and include retryWrites=true&w=majority in the URI
  • Install mongoose or mongodb in dependencies (not devDependencies)
  • Implement a singleton connection pattern for serverless Next.js or use MongooseModule.forRoot in NestJS
  • Set sensible options: maxPoolSize, serverSelectionTimeoutMS, and disable buffering when appropriate
  • Verify Atlas IP whitelist and that the DB user has minimal required permissions

Example use cases

  • Scan a Next.js project to ensure it uses a single shared MongoDB connection across lambda invocations
  • Check a NestJS monolith for correct MongooseModule.forRoot configuration and error handlers
  • Validate that CI/CD secrets include MONGODB_URI and that .env.example contains no credentials
  • Investigate repeated connection timeouts by confirming Atlas IP access and serverSelectionTimeoutMS
  • Prepare a deployment checklist by confirming driver installation and recommended connection options

FAQ

What URI format is required for Atlas?

Use mongodb+srv://<user>:<pass>@<cluster>/<db>?retryWrites=true&w=majority and URL-encode special characters in credentials.

Why use a singleton in Next.js?

Serverless environments can create many short-lived connections; a singleton prevents multiple concurrent connections and reduces connection churn.

What driver should I install?

Install mongoose for ODM features or mongodb for the native driver, and ensure they are listed in dependencies, not devDependencies.