๐ฆ Use MongoDB Atlas
This article helps you to setup a database with MongoDB Atlas for your Notification Service. Before you can start, make sure that you have an account for MongoDB Atlas.
tip
Student discount is available with the GitHub education pack. Click here for more information.
#
๐ง 1. Setup your databaseAs 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
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.
- 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>
ormyFirstDatabase
withmoodle-notification-service
. - 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 ๐ก 2. Get connection string from Atlas and append &ssl=true
at the end.
Example: