DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Data
  4. Migrating from Parse to Couchbase Mobile

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.

William Hoang user avatar by
William Hoang
·
Feb. 04, 16 · Tutorial
Like (1)
Save
Tweet
Share
3.68K Views

Join the DZone community and get the full member experience.

Join For Free

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);
gamescore.saveinbackground();

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");
document.putproperties(gamescore);

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.

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() {
    @override
    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())) {
            newrev.setproperties(mergedprops);
          } else {
              newrev.setisdeletion(true);
            }
        //saveallowingconflict allows 'rev' to be updated even if it is not the document's current revision.
            newrev.save(true);
        }
      } 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.

mobile app Data (computing) Database

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

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Secrets Management
  • How To Generate Code Coverage Report Using JaCoCo-Maven Plugin
  • Writing a Modern HTTP(S) Tunnel in Rust
  • Using AI and Machine Learning To Create Software

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: