CouchbaseLite synced documents

I’m having trouble understanding sync in CBL iOS. I’m using v1.4 and created a local database, a puller and a pusher, I set both to continuous and added the sync url. It seems that it syncs but I have no idea where the documents go. My sync url returns a json like this:

  "committed_update_seq": 548,
  "compact_running": false,
  "db_name": "beaconio",
  "disk_format_version": 0,
  "instance_start_time": 1489597104736843,
  "purge_seq": 0,
  "state": "Online",
  "update_seq": 548
}```

And my code goes like this:

    private static var SYNC_URL = URL.init(string: "MySyncUrl")
    
    private static var DEFAULT_DB_NAME = "test"
    
    private var database: CBLDatabase!
    private var puller: CBLReplication!
    private var pusher: CBLReplication!
    private var syncError: NSError!
    private var dbName: String!
    
    private var lEncrypt = true
    
    init () {
        dbName = CouchbaseObservable.DEFAULT_DB_NAME
        
        let dbOptions = CBLDatabaseOptions()
        dbOptions.create = true
        
        if(lEncrypt) {
            dbOptions.encryptionKey = "foo"
        }
        
        do {
            try database = CBLManager.sharedInstance().openDatabaseNamed(dbName, with: dbOptions)
        
        } catch {
            print("Error while opening the db")
        }
    }
    
    public func closeDatabase() throws {
        try database.close()
    }
    
    public func createDocument() -> CBLDocument {
        return database.createDocument()
    }
    
    public func getDocument(docId: String) -> CBLDocument? {
        return database.existingDocument(withID: docId)
    }
    
    public func startSync() {
        if database == nil {
            return
        }
        
        let url = CouchbaseObservable.SYNC_URL!
        
        pusher = database.createPushReplication(url)
        pusher.continuous = true // Runs forever in background
        NotificationCenter.default.addObserver(self, selector: #selector(replicationProgress(notification:)),
                                               name: NSNotification.Name.cblReplicationChange, object: pusher)
        
        puller = database.createPullReplication(url)
        puller.continuous = true // Runs forever in background
        NotificationCenter.default.addObserver(self, selector: #selector(replicationProgress(notification:)),
                                               name: NSNotification.Name.cblReplicationChange, object: puller)
        
        var auth: CBLAuthenticatorProtocol?
        auth = CBLAuthenticator.basicAuthenticator(withName: "test", password: "foo")
        pusher.authenticator = auth
        puller.authenticator = auth
        
        pusher.start()
        puller.start()
    }

But how do I get that json? Where is it stored? What method should I call to get it? I'm thinking maybe in the listener doing something like the following but I still don't get exactly **what** I should do there.

      @objc func replicationProgress(notification: NSNotification) {
        if pusher.status == .active || pusher.status == .stopped {
              // do something
        }
        
        if puller.status == .active || puller.status == .stopped {
              // do something
        }
      }

It seems that it syncs but I have no idea where the documents go.

The sync URL points to a database on a host that’s running a REST API listener/server. That database is where the documents go (on push) or come from (on pull.)

But how do I get that json? Where is it stored? What method should I call to get it?

I’m not quite sure what you’re asking. By “that json” you mean the documents in your database? You use the CBLDatabase instance to get documents by ID, and the CBLDocument instances to get their properties or store new properties.

We have a number of sample apps and tutorials that show how to do basic CRUD (create / read / update / delete) operations.

I’m thinking maybe in the listener doing something like the following but I still don’t get exactly what I should do there.

Those observer methods are for displaying progress indicators, for handling errors if the replication fails, and for finding out when replication completes. They’re not needed for adding docs to the database; the replicator does that automatically.

Could you describe more clearly what it is that you want to do?

I’m not quite sure what you’re asking. By “that json” you mean the documents in your database?

Yeah, the link to my actual db returns the json format above.

You use the CBLDatabase instance to get documents by ID, and the CBLDocument instances to get their properties or store new properties.

The thing is, if the replicator pulls the json as a document to the CBLDatabase instance, what’s the document ID? I didn’t set that up anywhere so it gives it an ID?

We have a number of sample apps and tutorials that show how to do basic CRUD (create / read / update / delete) operations.

I saw those, I also saw the adding sync ones but I find them kind of confusing, since the projects have a lot of code and almost no explanation.

Those observer methods are for displaying progress indicators, for handling errors if the replication fails, and for finding out when replication completes. They’re not needed for adding docs to the database; the replicator does that automatically.

Could you describe more clearly what it is that you want to do?

I wanted to send an event to a pub/sub object I have in my project, I thought doing it there would be the best, since then I’d know the documents had been synced and then I could pass the document as a json to my obj. Basically, something like:

MyPubSubObj.send("dataBasePull", myJsonObj)