SneakyHub
DiscordWebsiteBillingPanel
  • Information
    • Introduction
    • About Us
    • Guidelines
    • Terms and Conditions
    • Privacy Policy
  • Guides: How to
    • Earn Shards
    • Buy Shards
    • Create Server
    • Delete Server
    • Enable Cracked Mode on Minecraft Server
    • Redeem Codes
    • Transfer Shards
    • Use SFTP (WinSCP)
    • Vote for SneakyHub
  • Supported & Unsupported Software
    • Supported & Unsupported Software
  • NODE INFORMATION
    • Nodes Information
  • Troubleshooting
    • Error Code 500
    • Error Code 419
  • Discord Bots
    • Databases - MariaDB / MySQL
    • Databases - MongoDB
    • Creating a bot
    • Start up - DiscordJS(JavaScript)
    • Startup - DiscordJs(TypeScript)
Powered by GitBook

SneakyHub

  • Status
  • Panel
  • Billing

Websites

  • SneakyHub
  • SneakyHub - Forum

Social

  • Discord

The hosting company she told you not to worry about - SneakyHub 2021-2024

On this page
  • Did you join the SneakyHub discord server yet? If not, click here to join! Be sure that you also have a Discord bot already created. If not, refer to
  • ==========================
  • MongoDB Setup
  • Link to Discord Bot
  • Troubleshooting

Was this helpful?

Export as PDF
  1. Discord Bots

Databases - MongoDB

MongoDB is a Database system that you can use to connect your Discord bot to a databasing system!

PreviousDatabases - MariaDB / MySQLNextCreating a bot

Last updated 1 year ago

Was this helpful?

Did you join the SneakyHub discord server yet? If not, click to join! Be sure that you also have a Discord bot already created. If not, refer to Create Server

==========================

MongoDB Setup

We need to setup MongoDB before we continue. To do so, go to and signup / sign in. Once you've done that, fill out the first questions they ask until you appear onto a screen that's asking to deploy a database. For this tutorial, I will be using the M0 plan. Go ahead and click that. That will present some options if you scroll down. The main things you can change are the Provider, Region, and Name ( Figure 1A ). After you filled in all the fields, go ahead and press the Create button.

After, you'll be brough to this screen ( Figure 1B ). There are 2 customizable fields and 1 required one. You can choose what you want for the username and password. Be sure to click the Create User button. But where it asks to add whitelisted IP addresses, put in 0.0.0.0/0 so you are able to connect it to the Discord bot.

After it's filled out, press the green Finish and Close button to finish ( Figure 1C ). When asked about the setting up acccess rules, go ahead and click Go to Overview.

Click the green Connect button and press Drivers.( Figure 1D ) Copy the Step 3 code. You'll need that soon.

Link to Discord Bot

Now, go to your main Discord bot files. At the top of your file, add this line of code:

const mongoose = require('mongoose');

After, enter this other code anywhere in your code:

(async () => {
  try {
    mongoose.set('strictQuery', false);
    await mongoose.connect('PUT_YOUR_DRIVER_FROM_MONGO_HERE', { keepAlive: true });
    console.log('Connected to DB.');

    eventHandler(client);
  } catch (error) {
    console.log(`Error: ${error}`);
  }
})();

Be sure to enter your Driver information from MongoDB. Be sure after copying the connection string that you replace the password with the password you chose when generating the user.

After, go ahead and start your bot. If you set it up correctly, you should have this appear in console:

Troubleshooting

  1. Can't remember your password? Just go to Database Access => Database Users => Edit => Edit Password. After, go ahead to re-do your password. If you don't have a specific password, just press the Autogenerate Secure Password and it will automatically generate a new password for you.

Time to start linking MongoDB to SneakyHub. Go to the and go to your Discord bot server. Go to the Startup tab. Find the Additional Node Packages variable ( Figure 2A ). Enter into there mongoose.

Panel
here
MongoDB
Figure 1A
Figure 1B
Figure 1C
Figure 1D
2A