How Configure a MongoDB Atlas Database for your Parse Server
Tags: javascript, tutorial, typescript, devops
Published: 2022-12-01 13:58:14

_Originally posted on [ubiqueIoT](https://www.ubiqueiot.com/posts/parse-server-mongodb)_

In the [previous post](https://www.ubiqueiot.com/posts/parse-server-getting-started) 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](https://www.mongodb.com/cloud/atlas/register2) and login and create a new project.

![create new project 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x6rf40qqza1uoov8c97i.png)

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

![create database 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f34ozlepdj3ecuok1t1q.png)

![create database 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dewgieoay2fn1eozgxor.png)

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

![create database 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wspv1cbgcispmm16d2mq.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7si40vnvutlsbx4k2s6z.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k05kx4gt0m4t65yc9ndd.png)

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

![connect to your database 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rs4j0nfuqii6tkzfw1lf.png)

Connect using mongodb native drivers

![connect to your database 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uqxja6fkz8ep38tmwc7c.png)

Copy the connection string

![connect to your database 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jmzgdn2w0gneb0t6skcb.png)

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

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

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

![network access 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pffuowxq2cez5pofms7f.png)

![network access 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9cvuzlpuq5kt0td5iuus.png) 

 ❗️ 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.](https://www.youtube.com/watch?v=8NITVf0L5X0&ab_channel=50kT)

There are some valuable notes in [this guide](https://medium.com/@faridhajnal14/using-mongo-db-atlas-with-aws-elasticbeanstalk-5e97d2340453) 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.