mongodb-atlas-checker

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

MongoDB Atlas Checker

MongoDB Atlas 检查工具

Verify MongoDB Atlas setup and configuration. Identifies configuration issues, missing environment variables, incorrect connection strings, and ensures proper database setup.
验证MongoDB Atlas的安装与配置。识别配置问题、缺失的环境变量、错误的连接字符串,并确保数据库设置正确。

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
  • 验证MongoDB Atlas后端配置
  • 检查连接字符串配置
  • 验证环境变量设置
  • 排查数据库连接问题
  • 部署前审计数据库设置

Quick Checklist

快速检查清单

1. Environment Variables

1. 环境变量

  • 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
  • 存在
    MONGODB_URI
    (未硬编码)
  • 使用
    mongodb+srv://
    协议(Atlas必填)
  • 包含数据库名称
  • 包含
    retryWrites=true&w=majority
    参数
  • .env.example
    中不包含凭据

2. Connection String Format

2. 连接字符串格式

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

3. Driver Installation

3. 驱动安装

  • mongoose
    or
    mongodb
    package installed
  • In dependencies (not devDependencies)
  • 已安装
    mongoose
    mongodb
  • 位于dependencies中(而非devDependencies)

4. Connection Setup

4. 连接设置

  • Singleton pattern (Next.js)
  • MongooseModule.forRoot()
    (NestJS)
  • Error handling implemented
  • 单例模式(Next.js)
  • 使用
    MongooseModule.forRoot()
    (NestJS)
  • 已实现错误处理

5. Atlas Configuration

5. Atlas配置

  • IP whitelist configured
  • Database user exists with permissions
  • SSL/TLS enabled (default with
    mongodb+srv://
    )
  • 已配置IP白名单
  • 存在具备权限的数据库用户
  • 已启用SSL/TLS(使用
    mongodb+srv://
    时默认启用)

Common Issues

常见问题

IssueSolution
Missing
MONGODB_URI
Add to
.env.local
or
.env
Wrong protocolUse
mongodb+srv://
not
mongodb://
Multiple connections (Next.js)Use singleton pattern
Connection timeoutCheck IP whitelist in Atlas
Auth failedVerify credentials, URL-encode special chars
问题解决方案
缺失
MONGODB_URI
添加至
.env.local
.env
协议错误使用
mongodb+srv://
而非
mongodb://
多连接问题(Next.js)使用单例模式
连接超时检查Atlas中的IP白名单
认证失败验证凭据,对特殊字符进行URL编码

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
typescript
{
  retryWrites: true,
  w: 'majority',
  maxPoolSize: 10,
  serverSelectionTimeoutMS: 5000,
  bufferCommands: false,
}

如需详细的设置模式、验证脚本及完整示例:
references/full-guide.md