#
๐ Start your own bot with Heroku and MongoDB Atlas!This article helps you to run your own fmdb on Heroku and MongoDB Atlas. Both products are useful as they are part of GitHub's education pack. ๐ So if you are a student or a pupil make sure, you checked it out! Because then you can run one Hobby Dyno for free, what is necessary for this use case.
Before you start, follow the steps described here.
#
PreparationYou need
- an account on Heroku
- an account on MongoDB Atlas
- a
.env
file from these steps.
#
1. Setup you MongoDBAs this is a bit more complex, please follow the steps (parts) 1 to 4 of the official "Get Started with Atlas" article. After you completed 1 to 4, came back here and continue your setup.
Please note for the single steps:
- Part 1:
- Choose 'MongoDB Atlas'
- Part 2: nothing :)
- Part 3:
- Click on
Allow access from everywhere
- Click on
caution
Warning from MongoDB Developer: you probably don't want to allow this type of access in a production environment. Instead, you'll want to identify the exact IP addresses you know your application will be hosted on and explicitly set which IP addresses, or IP ranges, should have access to your cluster. After setting up your Heroku app, follow the steps in the "Configuring Heroku IP Addresses in Atlas" section below to see how to add the proper IP addresses for your Heroku app.
- Part 4:
- Choose a username as you like :)
- Choose a strong password! and keep it, you will need it during the next steps
#
2. Get connection string from AtlasNow it's time to get the connection string you will need for the .env-variable "MONGO_HOST". It will look something like mongodb+srv://<username>:<password>@clustername.mongodb.net/test?retryWrites=true&w=majority&useNewUrlParser=true&useUnifiedTopology=true
.
- In Clusters view, click Connect for the cluster to which you want to connect.
- In Choose a connection method view, click Connect your application.
- Select Node.js from the Driver dropdown.
- Copy the provided connection string from the Connection String Only dialog tab.
- Replace
<dbname>
withfmdb
. - Replace
<password>
with the password from cluster setup :) (Not the password of your MongoDB Atlas account!) - Save the link. You will need it during the next steps.
note
Note from docs.atlas.mongodb.com: The connection string displayed in the console uses a placeholder value for the password. Replace that placeholder with the password specified when you created your database user.
If the password contains reserved URI characters, you must escape the characters. For example, if your password is @bc123, you must escape the @ character when specifying the password in the connection string, such as %40bc123. To learn more, see Special characters in connection string password.
#
3. Update your environment variablesOpen your .env
file, set MONGO_HOST=
to the string you got from step 1 and append &ssl=true
at the end.
Example:
#
4. Create a new app on Heroku with just a clickClick here:
- Give your application a fancy name and choose your region
- Give it a name and fill all empty environment variables with the values of your
.env
file. - Click "Deploy App" and see the magic happen ๐ฎโจ
#
โ Yeah!You have successfully deployed your own fmdb to heroku! Within the build log you can find the url to access the admin panel.
note
When the fmdb freshly starts, the discord cache will be empty. Maybe as a spam bot protection, the bot is only able to send messages to users it already knows. Send the bot a small "test" message to add your admin (discord) account to bots cache.