MongoDB Connection Guide

Setting Up MongoDB Atlas

  1. Create a MongoDB Atlas account

    Go to MongoDB Atlas and sign up for a free account if you don't already have one.

  2. Create a new cluster

    After signing in, create a new cluster. The free tier (M0) is sufficient for development.

  3. Set up database access

    In the left sidebar, go to "Database Access" and click "Add New Database User". Create a user with a username and password. Make sure to give this user "Read and Write" permissions.

    Important: Remember this username and password as you'll need them for your connection string.
  4. Set up network access

    In the left sidebar, go to "Network Access" and click "Add IP Address". For development, you can add your current IP address or use "0.0.0.0/0" to allow access from anywhere.

  5. Get your connection string

    Go back to your cluster and click "Connect". Choose "Connect your application". Select "Node.js" as the driver and copy the connection string.

    mongodb+srv://<username>:<password>@cluster0.mongodb.net/document-manager

    Replace <username> and <password> with the credentials you created earlier. Add /document-manager at the end to specify the database name.

Adding the Connection String to Vercel

  1. Go to your Vercel project

    Log in to your Vercel account and select your project.

  2. Add environment variable

    Go to "Settings" → "Environment Variables". Add a new environment variable with the name MONGODB_URI and paste your connection string as the value.

  3. Redeploy your application

    After adding the environment variable, redeploy your application for the changes to take effect.

Common Connection Issues

Authentication Failed

This usually means your username or password in the connection string is incorrect. Double-check your credentials and make sure special characters in the password are properly URL-encoded.

Connection Timed Out

This could be due to network issues or IP restrictions. Make sure your IP address is whitelisted in the MongoDB Atlas Network Access settings.

Host Not Found

This means the cluster hostname in your connection string is incorrect. Make sure you're using the correct connection string from MongoDB Atlas.

Permission Denied

This means your user doesn't have the necessary permissions. Make sure the user has at least "Read and Write" permissions for the database.

Testing Your Connection

Use our Database Diagnostics Tool to test your MongoDB connection and get detailed information about any issues.

The diagnostics tool will check your connection string, attempt to connect to the database, and provide specific recommendations for fixing any problems.

Need More Help?

If you're still having trouble connecting to MongoDB, check theMongoDB Connection String DocumentationorMongoDB Atlas Troubleshooting Guide.