🚀 Setup Steps
Create a MongoDB Atlas Account
- Go to the MongoDB Atlas website.
- Sign up for a free account using your email or register with Google/GitHub.
- Complete the brief onboarding questionnaire.
Deploy a Free Shared Cluster
- Once logged in, click on Create a Deployment (or Build a Database).
- Choose the M0 (Free) tier. This tier is completely free forever and provides up to 512MB of storage, which is more than enough for the bot.
- Select your preferred Cloud Provider (e.g., AWS) and a Region close to your hosting environment or geographical location.
- Set your cluster name (default is
Cluster0) and click Create.
Configure Database Access (Credentials)
During the cluster creation process (or under Security > Database Access in the left sidebar):
- Set a Username (e.g.,
razor-admin). - Generate or set a secure Password.
- Ensure the user role is configured for Read and write to any database (Atlas admin).
- Click Create Database User.
Configure Network Access (Whitelist IP)
To allow your bot server (whether running locally or on a VPS) to communicate with MongoDB Atlas:
- Under the Security > Network Access tab in the left sidebar, click Add IP Address.
- Select Allow Access from Anywhere (this adds
0.0.0.0/0).
Why Allow Access from Anywhere?If you host the bot on your local PC or a dynamic cloud provider (like VPS, Heroku, etc.), your server’s IP address will change frequently. Whitelisting
0.0.0.0/0 ensures your bot never loses database connection.- Click Confirm and wait for the status to turn from Pending to Active.
Obtain Your Connection String
- Navigate to the Database (or clusters) page in the left sidebar.
- Click the Connect button next to your cluster.
- Choose Drivers under the connection options.
- Choose Node.js as your driver and select the latest version.
- Copy the connection string template. It will look like this:
Configure Your Environment File
- Open your bot’s project folder in your editor (e.g., VS Code).
- Open your
.envfile (if you haven’t created one, rename.env.exampleto.env). - Paste your connection string into the
MONGODB_URLvariable. - Replace
<db_username>with your database user’s username. - Replace
<db_password>with the password you saved in Step 3. - Specify a database name (e.g.
razor) right before the?query parameters.
.env line should look:🔍 Troubleshooting Connections
If your bot crashes or outputs database connection errors on startup, verify the following:- Special Characters in Passwords: If your database password contains special characters like
@,:,/, or+, you must URL-encode them (e.g.,@becomes%40), or recreate the database user with only letters and numbers. - IP Access Whitelist: Double check Network Access in MongoDB Atlas. If
0.0.0.0/0is not active or has been deleted, the cluster will reject your bot’s connection. - Accidental Brackets: Do not keep
<or>brackets around your password or username in the.envURL.- ❌ Incorrect:
mongodb+srv://<razor-admin>:<password>@... - Correct:
mongodb+srv://razor-admin:password@...
- ❌ Incorrect:
