Sample project for two way data sync

Hello,

I am new to use Couchbase lite framework on iOS. I want to have bidirectional data sync between mobile app and server using couchbase. What is the best sample that Couchbase has it now? Where it is located to download and see? I saw an example “GrocerySync”, but I don’t understand what this sample project doing. it does’t look like for two way data sync. Is there any sample Couchbase iOS sample project to show two way data sync between server and client?

FYI

Share extensions are great for sharing data with your app and the Web. Setting up a Share Extension to fetch documents on-demand from Sync Gateway is a good way to give more context awareness to the user. You then have the choice to save the document back to Sync Gateway through the REST API or in the Couchbase Lite database also used by your iOS application

Take a look at the tutorial in the docs https://developer.couchbase.com/documentation/mobile/1.4/training/index.html?language=ios. There are several sections, one of which is to enable push/pull replications.

I could see only Swift based tutorial, Is there any Objective C based? “GrocerySync” does also push / pull. Can I go ahead and follow this sample ? https://github.com/couchbaselabs/Grocery-Sync-iOS

Yes, you’ll need to add CBL. Instructions are on the README.

Yes, I have added Couchbase Lite framework in my project, following Readme from GrocerySync sample. Thanks.

Documents are really confusing. Is there any simple step by step procedure to just create a DB in iOS app, and push some data to Couchbase server via Couchbase sync ? Similarly data can be synced from server to iOS app? There are many steps confusing, who will create JSON file? Where it will be stored? Is there specific JSON format or we can have own own customer JSON format? I would like to have simple steps to just create/open a DB in iOS app (Objective C code), and push some data to Couchbase server via Couchbase sync.

Probably the reason there is no tutorial for “creating a database” is because it is just one or two lines. Here is a unit test written in Objective-C that creates a document. Once you have that database reference you can use it to create a replication as in the tutorial above.

Who will create the JSON file?

What JSON file? There are no JSON files, just JSON objects. The user creates them.

Where will it be store?

This is not a user-level concern. The only thing you need to know unless you are doing some low level debugging is that they are stored “in the CBLDatabase”

Is there any specific JSON format…?

What does this mean? JSON is JSON (i.e. strings, bools, arrays, objects, etc). If you mean schema, then no you are not required to follow any schema. The only requirement is that you don’t begin property names with an underscore.

1 Like

When I looked at example Couchbase lite iOS, it shows “sync_gateway_config.json” file to use. Do I need to copy and paste this file manually into Xcode project folder? Is it mandatory step? From where can I get this file?

Sample project json has the below format: How do i make one(json) for my data storage purpose? Can I reuse the same sample below JSON? Does any of my own json format being accepted by Couchbase server? Or I have to follow the below format strictly?
{
“log”: [“HTTP+”],
“databases”: {
“grocery-sync”: {
“server”: “http://localhost:8091”,
“bucket”: “grocery-sync”,
“users”: {
“GUEST”: {“disabled”: false, “admin_channels”: ["*"] }
}
}
}
}

Also, I just want to know what should I follow steps for the below task?

  1. What should I install first? Couchbase server? or Couchbase sync gateway?
  2. After Integrating Couchbase lite framework in the iOS project, what should i do for the following steps?
    i. I want to create DB or Open existing DB
    ii. How to insert data into DB and update to server?
    iii. How to insert data on the server and that can be synced to my iOS App?
    I couldn’t get straightforward tutorial for these steps, which is the ultimate of two way data sync.

Here’s a walkthrough that starts from scratch https://developer.couchbase.com/documentation/mobile/1.4/installation/ios/index.html#getting-started. Again, it’s Swift instead of ObjC so you will have to convert the code yourself. Most of the answers to your questions are in the docs so please take some time to read through. Individual code examples can be found in the CBL guides https://developer.couchbase.com/documentation/mobile/1.4/guides/couchbase-lite/native-api/database/index.html and SG guides https://developer.couchbase.com/documentation/mobile/1.4/guides/sync-gateway/index.html. Unfortunately it sounds like we don’t have the exact example you’re looking for. We take your feedback very seriously though and will refer to it in the next “version” of the getting started page. Thanks

Regarding the questions, we’re happy to help with 1 or 2 questions but 13 is just too much to handle in one go :slight_smile:

In addition to the resources already mentioned, here is another fairly simple app that should get you started with data replication and should hopefully answer most of your questions (Its in swift but it should be straightforward to map to ObjC)

git clone git@github.com:couchbaselabs/couchbase-lite-ios-standalone-sampleapp.git
git checkout syncsupport

The corresponding Blog :
https://blog.couchbase.com/data-sync-on-ios-couchbase-mobile/

sync_gateway_config.json is an example of a configuration file for Sync Gateway. It has nothing to do with Couchbase Lite. The JSON you’re included here is the contents of a typical Sync Gateway configuration, so, again, it has nothing to do with Couchbase Lite.

You should start by integrating Couchbase Lite into an iOS project. Try creating and storing information in the local database. Then learn about Sync Gateway and try that out.

You can read a series about trying out the whole stack here: https://blog.couchbase.com/getting-comfortable-with-couchbase-mobile-installing-couchbase-server/