Migrating from Parse to Couchbase Mobile

DZone 's Guide to

Migrating from Parse to Couchbase Mobile

Check out this awesome guide on how to migrate from Parse to Couchbase Mobile, including​ a look at what Couchbase Mobile is and how it can aid your Parse app.

· Mobile Zone ·
Free Resource

To mobile developers who are new to Couchbase Mobile, Data and Databases are what we at Couchbase do best. And we are not leaving you.  With the recent announcement that Parse will be shutting down indefinitely, developers are thinking how to transition their Parse mobile applications to another service or otherwise their mobile app will stop working. Along with another service comes with needing to also find an alternative hosted solution such as Digital Ocean where before Parse provided the backend hosting at a cost for your mobile applications. Let us explore how Couchbase can help with your apps.

What is Couchbase Mobile and How Can it Help With Your Parse App

Couchbase Mobile is a scalable open source local data store solution for your mobile application.  This means your mobile apps are able to store data on the device for offline usage without relying on the network for content. The solution is available across all mobile platforms as well as the browser where the connected backend is a NoSQL solution called Couchbase Server. Through the various supported client and backend SDKs, your mobile application will not only now have an offline experience for your users but it is backed by a database that is scalable, super fast, consistent and always available. And just like in Parse, the data is schemaless where you do not need to specify what keys need to first exist.

Storing data on Couchbase Mobile is similar to storing data on Parse. The key-value pairs in the 'ParseObject' are equivalent to the JSON-compatible data in Couchbase. On Android, let us compare the code between saving data in Parse versus saving data in Couchbase Lite where both the interfaces is similar to a 'Map'. Below you can see where the ParseObject class is referenced: 

ParseObject gameScore = new ParseObject("GameScore");
gameScore.put("score", 0129);
gameScore.put("playerName", "SooA Lim");
gameScore.put("cheatMode", false);

With the same data being stored now in Couchbase Lite for Android, you can see how the 'Map' is created and saved in a document database:

Map<String, Object> gameScore = new HashMap<String, Object>();
gameScore.put(“score", “0129");
gameScore.put(“playerName", “SooA Lim");
gameScore.put(“cheatMode", “false");

The difference here is that in Couchbase Mobile, when you call the 'putProperties' method and pass in the Map object, 'gameScore', you would have already persisted the JSON data locally on your mobile device. There is no additional code that needs to be called like 'Parse.enableLocalDatastore()' in your Application constructor; nor is there any additional calls to 'Parse.initialize()' to enable the data store to have a local storage. Couchbase Lite is the local storage component that lets you take your mobile apps offline and with complete data synchronization.


Storing data on your mobile device is a huge value that Couchbase Mobile provides much like Parse as we know how mobile UX is dramatically improved when there is a local database. But the difference with Syncing data from the device to the cloud with Couchbase is that the conflict resolution feature exists and is completely handled by Couchbase. While in Parse, you would need to write your own complex Cloud Code before to save any handler as resolution conflicts do not exist. What this means is that you as a developer have to handle the concurrency and management of the latest version of data in the server and then merge or delete accordingly. 

This is quite a lot of work overall as well as difficult and for Couchbase Mobile, you are not only able to efficiently synchronize data but also have the entire conflict resolution headache resolved by the system. No more needing to avoid the issue of conflicts. Simply just enable Sync Gateway from Couchbase to be your data transport component between mobile and server, and you will not have to worry about multiple users updating or changing the same keys ever again. Let us take a look at how to resolve conflicts in Android from the mobile application level. The Couchbase Document class contains an API called 'getConflictingRevisions()' where all the current conflicting Revisions for the Document is returned.  

final Document doc = database.getDocument(myDocID);
final List<SavedRevision> conflicts = doc.getConflictingRevisions();
if (conflicts.size() > 1) {
  database.runInTransaction(new TransactionalTask() {
    public boolean run() {
      try {
        Map<String, Object> mergedProps = mergeRevisions(conflicts);
        //Delete conflicting revisions to get rid of conflict:
        SavedRevision current = doc.getCurrentRevision();
        for (SavedRevision rev : conflicts) {
          UnsavedRevision newRev = rev.createRevision();
          if (rev.getId().equals(current.getId())) {
          } else {
        //saveAllowingConflict allows 'rev' to be updated even if it is not the document's current revision.
      } catch (CouchbaseLiteException e) {                                  
          return false;
      return true;

In the code snippet above, the 'getConflictingRevisions()' returns multiple revisions of the document if a conflict does indeed exist.  In a few lines of code, we are able to delete and merge revisions. Another way as well to resolve conflicts is simply having Couchbase pick a random winner by default. Let us first take a deep look and see about Parse and Couchbase Mobile compare and contrast from a features point of view now.      

Couchbase Mobile and Parse

Parse being a Mobile Backend as a Service provided a hosted solution for developers with their mobile applications. The additional features that Couchbase Mobile offer for your applications beyond Parse is:

Get Started

How to start preparing for the change is to first get set up with your own Couchbase instance in the cloud. This guide goes through how to set up Couchbase with Digital Ocean as this will prepare us to migrate the data that exist in Parse's Cloud Code over to Couchbase Server.

Database Migration

You can power your Parse app using your own Couchbase instance that you host. Using your own Couchbase database instance and migrating your database, you will then be able to:

  • Fully backup your entire database periodically and on demand
  • Increase performance of queries by providing larger amounts of dedicated processing power and memory to your database
  • Conflict resolution and eliminate risk of another app impacting the performance
  • Control your data and gain direct raw access to your application data

Exploring Couchbase Mobile

Learn more about why Couchbase Mobile is a great solution for modern app development and connect with the community for any questions on Stackoverflow or our mobile developer forums. Be sure to head over to the mobile portals to learn more on how to get started and stay tuned for future blogs on how to migrate from your Parse apps to Couchbase Mobile in our Coffee on Couchbase series.  


Published at DZone with permission of William Hoang , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}