Close

How to migrate Parse DB to self-hosted MongoDB?

Parse, a back-end service provider for mobile applications, has officially announced its retirement and will be completely phasing out its deployment on January 28, 2017. Unfortunately, this might be one the worst nightmares for SMEs who very much rely on Parse Server. Turning out to be an open source platform, Parse Server lets you to switch the Parse API to any infrastructure or data base which can host Node.js applications.

Following is a migration guide on how to migrate Parse DB to self-hosted MongoDB.

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

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 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 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 an new express application using 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 ‘http://localhost:1337/parse’.
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.

 

I hope this blog provides you an idea about migrating Parse DB to self-hosted MongoDB. If you are struggling with Parse DB migration or you want to migrate to AWS or any other data base or cloud server, shoot an inquiry right away to our most expert architect, Jerry Don, at [email protected].

Latest stories

  • 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 […]

  • How to Create Mobile App Wireframe?

    Do you have an awesome app idea? Awesome!  No matter how amazing your idea for a mobile app is, if you are clueless about where to start and how to go about the development, it is bound to fail. So, after finalizing the app idea, the next step is wireframing. Why Wireframing? Incorporating all the […]

  • Designing The Ultimate Mobile App Architecture

    The strength of a building lies in its foundation. Similarly, architecture is the backbone of any mobile application. Building better app architecture is vital for the success of an app. Even the smallest fault in the architecture can undermine the quality of the app.  Factors to Consider While Developing Mobile App Architecture Before you dive […]

Leave a Reply

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