Go to MongoDB Atlas and sign up for a free account if you don't already have one.
After signing in, create a new cluster. The free tier (M0) is sufficient for development.
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.
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.
Go back to your cluster and click "Connect". Choose "Connect your application". Select "Node.js" as the driver and copy the connection string.
Replace <username> and <password> with the credentials you created earlier. Add /document-manager at the end to specify the database name.
Log in to your Vercel account and select your project.
Go to "Settings" → "Environment Variables". Add a new environment variable with the name MONGODB_URI and paste your connection string as the value.
After adding the environment variable, redeploy your application for the changes to take effect.
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.
This could be due to network issues or IP restrictions. Make sure your IP address is whitelisted in the MongoDB Atlas Network Access settings.
This means the cluster hostname in your connection string is incorrect. Make sure you're using the correct connection string from MongoDB Atlas.
This means your user doesn't have the necessary permissions. Make sure the user has at least "Read and Write" permissions for the database.
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.
If you're still having trouble connecting to MongoDB, check theMongoDB Connection String DocumentationorMongoDB Atlas Troubleshooting Guide.