Close

How to migrate from Parse to MongoDB and AWS?

Earlier, we had written a very informative tutorial on how to migrate Parse DB to self-hosted MongoDB. Well, this article will take a step forward reaching out to AWS Parse migration.

Overview

Parse Server is an open source version of the Parse backend that can be deployed to any infrastructure that can run Node.js. Parse is a Mobile Backend as a Service platform.
Parse Server was built in Node.js and works with the Express web application framework. It can be added to existing web applications, or run by itself.

Specifications

  • Parse Server is not dependent on the hosted Parse backend.
  • Parse Server uses MongoDB directly and is not dependent on the Parse hosted database.
  • You can migrate an existing app to your own infrastructure.
  • You can develop and test your app locally using Node.

Prerequisites

  • Node >=4.3
  • MongoDB version 2.6.X or 3.0.X
  • Python 2.x (For Windows users, 2.7.1 is the required version)
  • For deployment, an infrastructure provider like Heroku or AWS

Existing App in Parse.com

parsedb-migration-1

After migration to parse server

parsedb-migration-2

Migrate Parse DB to Self-Hosted MongoDB

Using your own MongoDB instance and infrastructure will help ensure that your  queries will run at their highest level of performance. By migrating your database, you will be able to:

  • Backup your entire database periodically and on demand.
  • Restore backups.
  • Increase performance of queries (and thereby your app) by providing larger amounts of dedicated processing power and memory to your database.
  • Eliminate risk of another app impacting the performance of your app’s queries.
  • Gain raw access to your application’s data.
  • Modify, add or fine-tune indexes on your most popular or complex queries.

Use the database migration tool to transfer your data from parse.com ( App Settings → General → Migrate to an external database ). Add your MongoDB URL in the textbox.Make sure the URL contains admin privileges.A new collection will be added to your database specified in MongoDB URL. Make sure it contains all the data as in parse.com.Now you can use this collection for further querying.

Set Up Local Parse Server (nodejs and express)

We are using an express application with a parse-server module. Earlier the URL contains domain name as ‘api.parse.com’, but now we can change it to our own domain name (localhost too).

Create a new express application using an express generator if you didn’t have any express application. Make sure the nodejs version is >=4.3

Follow the below steps:

1. Install parse-server module using npm (version >=2.1.4)npm install -g parse-server

2. Create a new folder named ’cloud’ in the root directory. Add a new file ‘main.js’ to this folder. This file will contain all the parse defined functions.

3. Create an instance of Parse Server in your server file (app.js)
var api = new ParseServer({
databaseURI: '<mongodb://your.mongo.uri>',
cloud:’’,
appId: '',
fileKey: '',
masterKey: '',
serverURL: ‘http://localhost:1337/parse’
});

4. If you are using Parse Hosting, you can migrate all these web endpoints to the same Express app that is serving Parse Server. For example, you could mount Parse Server under /parse and your website at the root, like so:app.use(‘/parse’, api);

So that all the parse defined functions will be loaded in the url with

app.use('/parse', api);

5. We will now migrate your existing Cloud Code to run in Parse Server. Copy your app’s Cloud Code to the application ‘cloud/main.js’

A sample function is given below:
Parse.Cloud.define("list", function(request, response) {
var query = new Parse.Query('TableName')
query.find({
error: function(err) {
response.error(err)
},
success: function(res) {
response.success(res)
}
})
});

This will list all the data inside the collection ‘TableName’

6. Now the express app is all set to run the parse query.Run the application ‘http://localhost:1337’ in browser and check whether its
running.

7. Run the query

curl -X POST  -H "X-Parse-Application-Id: YOUR_APP_ID" \
http://localhost:1337/parse/functions/list

8. Now you will see the list of data inside the collection.

Deploy the application to AWS

Clone this application from github to aws.
You are now ready to start your parse-server app.

  1. npm install
  2. npm start

Make sure you have changed the ‘serverURL’ and ‘databaseURI’ inside the parse instance from localhost to production url.
Try running the application using the production url.

Note : On January 28, 2017, any calls to the hosted Parse backend service (api.parse.com) will cease to function.

Latest stories

  • 7 Proven Hacks to Enhance Your Mobile App User Experience

    In this digital age of fierce competition, quality and performance easily outweigh brand loyalty. Creating a fluid user experience is essential for the  success of any mobile app. Efficient user experience UX is the backbone of a visually appealing and engaging app. It can either make or break an app.  Here are a few considerations […]

  • Things To Know About App Testing During Development

    With years of experience in app development and testing, we give utmost importance to quality assurance in mobile application development. Our team of adroit software testers ensures that quality assurance is an integral part of the development lifecycle right from ideation to deployment and in post-development reviews. Here are a few things the QA engineers […]

  • Go Live: 6 Things To Do Before Publishing an App

    After years of publishing applications to the app store, our team has come up with a checklist showcasing important things to do before publishing your app on Google Play or Apple App Store. Without further ado, let’s get started.  #1.Thoroughly Understand The App Store Policies and Guidelines It is vital to understand the app publishing […]

Leave a Reply

Your email address will not be published. Required fields are marked *