Building a New Parse Server & MongoDB Atlas-Based Application

September 11, 2016

Editor's note: This post was edited on November 11, 2016 to reflect the addition of MongoDB Atlas as a Parse migration endpoint.

Whether you're migrating from the deprecated Parse.com (api.parse.com) or building a new application, the Parse Server community is alive and strong, and since Parse Server version 2.1.11, there is support for MongoDB 3.2 which makes MongoDB Atlas an ideal back-end for Parse Server based applications.

Existing hosted Parse / api.parse.com users can migrate their back-end using Parse's Database Migration tool directly to MongoDB Atlas using a connection string like the following (with bold items replaced with your details):

 mongodb://username:password@node1.mongodb.net:27017,node2.mongodb.net:27017,node3.mongodb.net:27017/applicationDbName?replicaSet=clusterName-shard-0&ssl=true&authSource=admin

We will learn in this blog post:

  • How to deploy a MongoDB Atlas cluster
  • How to deploy the Parse Server (in our case we will show how to do so using AWS Elastic Beanstalk quick start, but updated to use the newest version of Parse Server)
  • How to configure Parse Server to connect to MongoDB Atlas
  • How to confirm connectivity

How to set up a new sample Parse Server application with a MongoDB Atlas back end:

  1. Deploy MongoDB Atlas cluster
  2. Consider sizing options but start small for a hello world style application. You can always scale later (MongoDB Atlas allows you to migrate to larger instances with no downtime to your database).
  3. Register for MongoDB Atlas at mongodb.com/atlas
  4. Build and deploy your first cluster (we’ll use a small M10 instance-sized replica set for our example, and deploy it into the US East region)
  5. We’ll Create a user with at least readWrite on the applicationDbName database (or the user with readWriteAnyDatabase@admin which gets created automatically will do)
  6. For testing purposes, we will open IP address to all IP addresses initially (0.0.0.0/0): Later we should leave only open to our application servers’ public IP addresses.
  7. Choose where and how you want to deploy the Parse Server:
  8. Many options are described here, some of which provide easier set-ups than others. AWS Elastic Beanstalk and Heroku are easy options.

For purposes of this blog post, we will go with AWS Elastic Beanstalk for the Parse Server quick start, by following the URL below (requires AWS account):

  1. Click for AWS Elastic Beanstalk for the Parse Server quick start deployment example.
  2. But we will make sure we install Parse Server 2.1.12 or higher, e.g. in parse-server-example, ensure that the package.json file includes "parse-server": "~2.2.16" (where 2.2.16 is the current latest at time of this writing).
  3. The Parse Server Example can be downloaded from github:
  4. If we extract the Zip file, we can edit the version in package.json
  5. We’ll set the Parse Server version to 2.2.16 (latest at time of writing)
  6. We’ll select the files in the directory and re-compress them into a new Zip file
  7. We’ll upload our new zip file so that it can be deployed
  8. Configure Parse Server to connect to MongoDB Atlas
  9. Inside the AWS Elastic Beanstalk UI
  10. We’ll navigate to the “Configuration” section on the left-hand menu
  11. Then we’ll navigate to the “Software Configuration” section by clicking the gear icon, and scroll down to the “Environment Properties” section
  12. In the environment properties, we’ll use any myAppId, myFileKey, mySecretMasterKey we want (since this is a new application, we set these).
  13. We’ll set the SERVER_URL to that which shows near the top of our AWS Elastic Beanstalk application UI to the right of “URL: ...“
  14. We’ll set the DATABASE_URI as follows (replacing the bold text with our specific cluster’s details)
  15. mongodb://username:password@node1.mongodb.net:27017,node2.mongodb.net:27017,node3.mongodb.net:27017/applicationDbName?replicaSet=clusterName-shard-0&ssl=true&authSource=admin
  16. We can see what the appropriate MongoDB URI should be inside of MongoDB Atlas’s “Connect” UI for the cluster, under the Driver connections section
  17. Test to confirm connectivity of our example application to Parse Server and the MongoDB Atlas backend:
$ curl -X POST \
> -H "X-Parse-Application-Id: newParseTest" \
> -H "Content-Type: application/json" \
> -d '{"score":1337,"playerName":"John Doe","cheatMode":false}' \
> http://parseserver-365pk-env.us-east-1.elasticbeanstalk.com/parse/classes/GameScore
Returns:
{
  "objectId": "YMgGV6kVTP",
  "createdAt": "2016-08-26T14:54:26.580Z"
}
$ curl -X GET \
> -H "X-Parse-Application-Id: newParseTest" \
> -H "X-Parse-Master-Key: MASTER_KEY" \
> http://parseserver-365pk-env.us-east-1.elasticbeanstalk.com/parse/classes/GameScore
Returns:
{
  "results": [
    {
      "objectId": "YMgGV6kVTP",
      "score": 1337,
      "playerName": "John Doe",
      "cheatMode": false,
      "createdAt": "2016-08-26T14:54:26.580Z",
      "updatedAt": "2016-08-26T14:54:26.580Z"
    }
  ]
}

Now you can use the SDK to build a new application pointing to your instance of Parse Server + MongoDB Atlas!

Sign up for MongoDB Atlas and get started today!


About the author - Andrew Davidson

Andrew is a product manager at MongoDB responsible for MongoDB's suite of cloud products including MongoDB Atlas and Cloud Manager. Andrew played a major role in the success of MongoDB's on-prem management tool, Ops Manager.

Before joining MongoDB, Andrew worked with Google for 3 years after earning his physics degree at UC Berkeley.

Previous Article
In the Loop with Hadoop - Take Advantage of Data Locality with mongo-hadoop
In the Loop with Hadoop - Take Advantage of Data Locality with mongo-hadoop

Imagine that you’ve been tasked with a big question: count how many times each word occurs in the complete ...

Next Article
Bringing MongoDB and Microservices to UPS i-parcel
Bringing MongoDB and Microservices to UPS i-parcel

How does the UPS i-parcel service give online shoppers a native checkout experience in more than 100 countr...