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

  • If you are in Jordan looking for app development support you should read this

    From downloading a mobile app  to visiting a brick-and-mortar store, customers today value every interaction with a brand. A great customer experience leaves a lasting impression in their minds about the happy and satisfying experience.  Winning the customer experience race Every  interaction offers  a make-or-break opportunity for a brand to either  build a loyal customer […]

  • Enhanced Efficiency & Optimized Cost of Project Development with Sweden Hybrid Model.

    Going beyond the cost factor and striving to deliver quality, innovation and flexibility to its customers across the globe, Toobler introduced a Hybrid (Onshore and Offshore) Software Development Model. Huge popularity of the hybrid model is fuelled by scores of organizations choosing to keep design and architecture phases at geographic proximity.  Driven by a customer-centric […]

  • 7 Pro Tips: Network Like a Boss at GITEX 2019

    The biggest tech show in the Middle East, North Africa & South Asia- GITEX Technology week takes place in Dubai World Trade Centre from Oct 6 – Oct 10. The opportunity to network with prospects, key decision-makers and business heads of the tech industry makes GITEX an unmissable event.  What makes the show exceptional is […]

Leave a Reply

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