Couchbase Mobile

Migrating from Parse to Couchbase Mobile

4 MIN DE LEITURA

Couchbase Mobile is the NoSQL database solution for mobile. It has an embedded NoSQL database (Couchbase Lite), built-in synchronization (Sync Gateway), and is all backed by a highly scalable and performant NoSQL database server (Couchbase Server).  

With the recent announcement that Parse will be shutting down indefinitely, developers are left to figure out how to migrate  their Parse mobile applications to another technology.

Below is a simple example of how you can migrate an existing Parse app to Couchbase Mobile, backed by Digital Ocean.

Storing data in Couchbase Mobile is similar as storing data in Parse.  The key-value pairs in the ‘ParseObject’ is equivalent to a document in Couchbase.  On Android, let us compare the code between writing data in Parse versus writing data in Couchbase Lite. :

Here’s an example of writing data in Parse:

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

Here’s an example of writing data in Couchbase Lite:

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

As you see from this example, usage patterns in Parse and Couchbase Mobile are quite similar.

Synchronization

From a datastore perspective, Couchbase Mobile is a more complete solution. Couchbase is a full-stack database with integrated synchronization and security, and includes features like conflict resolution, events, REST API, Stream and Batch API, and more. Parse was limited in these types of capabilities.   

Here are some more examples of how you use the Couchbase Mobile database in your mobile code:

// Get the database (and create it if it doesn’t exist).
Manager manager = new Manager();
Database database = manager.getDatabase("mydb");

// Create replicators to push & pull changes to & from the cloud.
URL url = new URL("”https://www.my.com/mydb/");
Replication push = database.createPushReplication(url);
Replication pull = database.createPullReplication(url);
push.setContinuous(true);
pull.setContinuous(true);

// Add authentication.
Authenticator authenticator = AuthenticatorFactory.createBasicAuthenticator(name, password);
push.setAuthenticator(authenticator);
pull.setAuthenticator(authenticator);

// Listen to database change events.
database.addChangeListener(this);

// Start replicating.
push.start();
pull.start();

// Create a new document (i.e. a record) in the database.
Document document = database.createDocument();
Map<String, Object> properties = new HashMap<>();
properties.put("firstName", "John");
document.putProperties(props);                                                                                                                                                                                                                                                                                                                                                                                                                                                

Couchbase Mobile and Parse

Here is a coverage matrix of the major datastore features in Couchbase Mobile and Parse:

Couchbase Mobile Parse
Offline Read/Write
Read/Write Security Policies
Pluggable Authentication
Synchronization
Conflict Resolution
Query
Blob Storage
API REST
Batch/Bulk API
Changes Stream
Webhooks
Self Hostable
Open Source

Get Started

As a next step,  you can setup your own Couchbase in the cloud.  This guide goes through how to set up Couchbase with Digital Ocean. After you’ve set up your Digital Ocean instance, you can begin to migrate your app  data from Parse’s Cloud Code to Couchbase Server.

Database Migration

Ultimately, moving from Parse to Couchbase will allow you to:

  • Securely store and access data both locally and in the cloud
  • Securely synchronize your data between the cloud and other devices
  • Elastically scale a capacity system as needed
  • Integrate with other systems
  • Share data between web and mobile

Exploring Couchbase Mobile

Learn more on 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 webinar series.

 

Compartilhe este artigo

Autor

William era um Developer Advocate na equipe de Mobile Engineering/Developer Experience na Couchbase. Seu amor por café e código o transcendeu para o mundo mobile, ao mesmo tempo em que aprecia as experiências presenciais offline. Antes, William trabalhou na equipe de Relações com Desenvolvedores no Twitter, BlackBerry e Microsoft, além de ter atuado como engenheiro de GPS embarcado de software na Research In Motion. William se formou em Engenharia de Software Elétrica pela Universidade McGill.

Deixe um comentário

Pronto para começar com o Couchbase Capella?

Começar a construir

Confira nosso portal para desenvolvedores para explorar o NoSQL, navegar por recursos e começar com tutoriais.

Use o Capella free

Coloque a mão na massa com o Couchbase em apenas alguns cliques. O Capella DBaaS é a maneira mais fácil e rápida de começar.

Entre em contato

Quer saber mais sobre as ofertas do Couchbase? Deixe-nos ajudar.