DEV Community

Eric Pietrowicz
Eric Pietrowicz

Posted on • Originally published at ubiqueiot.com

How Configure a MongoDB Atlas Database for your Parse Server

Originally posted on ubiqueIoT

In the previous post we set up a Typescript Parse Server instance. Now, let's get our server connected to a MongoDB Atlas instance.

First, create a Mongo Atlas account and login and create a new project.

create new project 2

Add a database to your project by choosing the Build a Database option in your new project.

create database 1

create database 2

Accept all of the defaults avoiding any paid tiers for now.

create database 3

Next, we'll need to add a new user that will be used to connect to the db. Keep note of your user account information, this will be used in our Parse code to connect to this instance.

add database user

Choose the Add My Current IP Address button so that your current IP address can connect locally to your database.

add IP address to your database

Once back in the main menu of your project, choose the connect option

connect to your database 1

Connect using mongodb native drivers

connect to your database 2

Copy the connection string

connect to your database 3

Paste the connection string to your index.js file under your databaseURI config:

databaseURI: 'mongodb+srv://<replace-with-username-(no-brackets)>:<replace-with-password-(no-brackets)>@cluster0.bh3ah.mongodb.net/?retryWrites=true&w=majority'
Enter fullscreen mode Exit fullscreen mode

Finally, go back to MongoDB Atlas and update the network access settings so that our ElasticBeanstalk instance can connect.

network access 1

network access 2

❗️ Please treat this as a temporary solution. When you go to production, you will need to set up a secure VPC connection between ElasticBeanstalk and MongoDB.

This is a great guide on how to configure VPC peering.

There are some valuable notes in this guide as well.

Let's run our Parse Server locally to make sure it can connect to the Mongo instance.

In your Parse project run npm run start and confirm that your server does not time out. It should now be connected to your database.

Latest comments (0)