Skip to content

Setting Up MongoDB

CPS edited this page Aug 21, 2024 · 1 revision

🚀 Setting Up MongoDB

Step 1: Create a MongoDB Atlas Account

  1. Visit the MongoDB Atlas website.
  2. Click on Start Free and sign up using your Google account or by entering your details manually.
  3. Once registered, log in to your MongoDB Atlas account.

Step 2: Create a New Cluster

  1. Click on Build a Cluster.
  2. Choose the free tier (shared cluster) and select your preferred cloud provider and region.
  3. Click on Create Cluster (this might take a few minutes).

Step 3: Create a Database User

  1. Once your cluster is ready, click on Database Access on the left-hand sidebar.
  2. Click on Add New Database User.
  3. Enter a username and password. Save these credentials as you'll need them later.
  4. Set the user’s role as Read and write to any database.
  5. Click Add User.

Step 4: Set Network Access

  1. Click on Network Access on the left-hand sidebar.
  2. Click on Add IP Address.
  3. Add your current IP address by clicking Add Current IP Address or allow access from anywhere using 0.0.0.0/0 (not recommended for production).
  4. Click Confirm.

Step 5: Get Your Connection String (Driver URL)

  1. Go back to your cluster and click on Connect.
  2. Choose Connect your application.
  3. Select the Node.js driver version that matches your Node.js version.
  4. Copy the provided connection string. It should look something like this:
mongodb+srv://<username>:<password>@cluster0.mongodb.net/<dbname>?retryWrites=true&w=majority

Step 6: Replace the Connection String Values

  1. Replace <username>, <password>, and <dbname> with your MongoDB username, password, and desired database name.

Step 7: Configure Your Bot with MongoDB

1. Update .env File

  1. Open your .env.example file.
  2. Replace the placeholder in the MONGO_URI field with your MongoDB connection string:
TOKEN=  #Your bot Token here
MONGO_URI=mongodb+srv://<username>:<password>@cluster0.mongodb.net/<dbname>?retryWrites=true&w=majority
CLIENT_ID= #Your Client id here
GUILD_ID= #Your Guild ID here if you want to register slashcommand only for specefic guild
  1. Rename .env.example to .env.

2. Update config.example.json File

  1. Open your config.example.json file.
  2. Replace the placeholder in the "uri" field with your MongoDB connection string:
{
    "clientId": "",
    "prefix": "!",
    "messages": {
        "COOLDOWN_MESSAGE": "You are on <duration> cooldown!"
    },
    "ownerID": [""], //put owner's user id here
    "adminId": [""], //put user id of people you want to make admin
    "uri": "mongodb+srv://<username>:<password>@cluster0.mongodb.net/<dbname>?retryWrites=true&w=majority",
    "nodes": [
        {
            "host": "",   //your lavalink ip here
            "identifier": "",//name your lavalink anything
            "password": "youshouldpass", //password of your lavalink
            "port": 12345, //port
            "retryAmount": 1000,
            "retrydelay": 10000,
            "resumeStatus": true,
            "resumeTimeout": 1000,
            "secure": false
        }
    ]
}
  1. Rename config.example.json to config.json.

Step 8: Test Your Bot with MongoDB

  1. Run your bot to ensure it's properly connected to MongoDB:
npm start
  1. If everything is configured correctly, your bot should start without any issues, and you can begin interacting with your MongoDB database.

🔗 Useful Links

This should get your MongoDB set up and integrated with your Discord bot!


Wiki Sidebar

  • Home

    • Introduction and Overview
    • Features and Capabilities
  • Installing and Configuring the Bot

    • Prerequisites
    • Installation Steps
    • Configuration Guide
      • .env Configuration
      • config.json Configuration
  • Connecting MongoDB

    • Setting Up MongoDB
    • Connecting MongoDB via Driver URL
    • Configuring MongoDB in Your Bot
  • Connecting Lavalink

    • Downloading and Setting Up Lavalink
    • Configuring Lavalink in Your Bot
    • Connecting the Bot to Lavalink
    • Troubleshooting Lavalink Connections
  • FAQ

    • Common Issues and Solutions
    • How to Enable Message Content Intent
    • Bot Permissions and Command Issues
    • Music Playback and Node Configuration
    • Admin Management and Token Changes

Clone this wiki locally