mLab, which is the service we use for our remote Mongo database, was acquired by MongoDB. They have now since closed off all new mLab registrations. MongoDB’s Atlas product is a free tier similar to mLab, albeit more powerful.
Here are the steps to set up a MongoDB account and Atlas cluster to use with the project:
1. Go to https://www.mongodb.com/atlas/database and click the Try Free button (or Sign In if you already have an account)
2. Create your MongoDB user account and click the Get started free button.
3. After creating your account, you will be prompted to accept the privacy policy and ToS. Click the Submit button to continue.
4. You should see a brief questionnaire. Select Learn MongoDB, Application Modernization, and JavaScript.
5. You will then be prompted to create a cluster. Select the far right Shared Free tier cluster option and click the Create button.
6. Leave all free tier options selected – AWS, North America: N. Virginia, etc. Click the Create Cluster button.
7. You will then be prompted with a security configuration screen. Enter a Username and click the Autogenerate Secure Password button. Copy this password to a safe place as you will need it a few steps from now.
8. Scroll down to the Where would you like to connect from section. Select My Local Environment. Then, enter 0.0.0.0/0 in the IP Address field. This will be very important to avoid connection errors especially if your IP address changes frequently, or, you develop from multiple locations (home, work, a coffee shop, etc). Click the Finish button.
9. You should next see a Congratulations popup modal. Click the Go to Databases button.
10. The cluster will take a few minutes or more to generate. Eventually, you should see a green circle to the left of the cluster name. Once you see the circle, click the Connect button.
11. Select Connect Your Application
12. Change the driver version to 2.2.12 or later. This is very important as newer driver versions will not work with the version of Mongoose the starter application has installed. Copy the entire connection stringand click the Close button. Head back over to your local application.
13. In your config/dev.js file create the mongoURI key-value pair if you haven’t already done so.
Remember the comma if adding in-between other key-value pairs:
googleClientID: 'redacted', googleClientSecret: 'redacted', mongoURI: '', cookieKey: 'redacted',
Add the connection string by pasting the entire address string you copied from the screen before.
mongoURI: 'COPY_THE_SRV_ADDRESS_STRING_HERE'
Remember to replace <password> with the Atlas user’s actual password.
Next, you must add an arbitrary database name to the connection string. In the example below we have added the name blog-dev after the slash and before ?ssl=true.
"mongodb://user:[email protected]:27017,cluster0-shard-00-01.uwsj6.mongodb.net:27017,cluster0-shard-00-02.uwsj6.mongodb.net:27017/blog-dev?ssl=true&replicaSet=atlas-ij7azh-shard-0&authSource=admin&retryWrites=true&w=majority",
14. Restart your local Node server if you have not already done so.
15. You should now be able to test logging in and adding a test post. You can navigate to the databases that were created by finding the Browse Collections tab.