Couchbase Lite client replicator does not receive any new updates on couchbase server via sync gateway, but push replication is working

I am trying to prototype a couchbase lite client that can sync with couchbase server database via sync gateway. Push replication is working fine, new document created by client can be replicated to server but any updates on the documents or existing documents on server cannot be replicated to client side. Below are the details of my setup:

Couchbase Server:

  • version: Enterprise edition 7.1.3 build 3479 (installed using APT)
  • OS: Ubuntu 20.04.2 LTS
  • created one bucket named “get-started-bucket” with no replicas enabled
  • created 3 users:
    1. username = sync_gateway, roles = Full Admin
    2. username = sync_gateway0, roles = Sync Gateway [get-started-bucket]
    3. username = sync_gateway1, roles = Sync Gateway Application [get-started-bucket:.]

Sync Gateway:

  • version: couchbase-sync-gateway-enterprise_3.0.5_x86_64
  • OS: Ubuntu 20.04.2 LTS
  • configuration file:
{
  "bootstrap": {
    "server": "couchbase://0.0.0.0", 
    "username": "sync_gateway", 
    "password": "password",
    "server_tls_skip_verify": true, 
    "use_tls_server": false 
  },
  "api": {
    "admin_interface_authentication": false, 
    "metrics_interface_authentication": false 
  },
  "logging": { 
    "console": {
      "enabled": true,
      "log_level": "debug",
      "log_keys": ["*"]
    }
  }
}

  • created one database named traveldb (see images attached for database configuration, i.e. role, user, channel, etc.)

Couchbase Lite Client (using C):

  • version: cblite v3.0.2 (install via apt)
  • OS: Raspbian Buster (version 10)
  • sample code to perform push and pull replication via sync gateway interface:
CBLError err;
CBLDatabase* database = CBLDatabase_Open(FLSTR("traveldb"), NULL, &err);
if(!database) {        
    fprintf(stderr, "Error opening database (%d / %d)\n", err.domain, err.code);
    return;
}
      
CBLDocument* newTask = CBLDocument_CreateWithID(FLSTR("xyz"));
FLMutableDict properties = CBLDocument_MutableProperties(newTask);
FLMutableDict_SetString(properties, FLSTR("type"), FLSTR("task"));
FLMutableDict_SetString(properties, FLSTR("owner"), FLSTR("todo"));
FLMutableDict_SetUInt(properties, FLSTR("createdAt"), time(NULL) * 1000);
CBLDatabase_SaveDocument(database, newTask, &err);
CBLDocument_Release(newTask);

CBLEndpoint* targetEndpoint = CBLEndpoint_CreateWithURL(FLSTR("ws://192.168.3.152:4984/traveldb"), &err);
if(!targetEndpoint) {
    printf("Failed to create endpoint...");
    return;
}
    
CBLReplicatorConfiguration replConfig;
CBLAuthenticator* basicAuth = CBLAuth_CreatePassword(FLSTR("sgwuser2"), FLSTR("password"));
memset(&replConfig, 0, sizeof(replConfig));
replConfig.database = database;
replConfig.endpoint = targetEndpoint;
replConfig.authenticator = basicAuth;
replConfig.replicatorType = kCBLReplicatorTypePushAndPull;
replConfig.continuous = true;
replConfig.disableAutoPurge = true;
    
CBLReplicator* replicator = CBLReplicator_Create(&replConfig, &err);
CBLAuth_Free(basicAuth);
CBLEndpoint_Free(targetEndpoint);
if(!replicator) {
    printf("Failed to create replicator...");
    return;
}
    
CBLListenerToken* token = CBLReplicator_AddChangeListener(replicator, simpleChangeListener, NULL);
    
CBLReplicator_Start(replicator, false);
    
while(CBLReplicator_Status(replicator).activity != kCBLReplicatorStopped) {
    printf("Waiting for replicator to stop...");
    const CBLDocument* doc = CBLDatabase_GetDocument(database, FLSTR("xyz"), &err);
    
    FLSliceResult docJson = CBLDocument_CreateJSON(doc);
    printf("Document in JSON :: %.*s\n", (int)docJson.size, (const char *)docJson.buf);
    usleep(500000);
}
CBLReplicator_Release(replicator);

**The document is updated on server by changing its value for the key “owner” but replicator on client side does not seem to be receiving any incoming messages from sync gateway.

Wondering what’s wrong with my configuration, any helps or suggestions would be much appreciated.

Thanks in advance~

This seems like it might be that the document is not in a channel accessible by the user. Read and write permissions are controlled separately, so it’s possible for a user to be able to write a document that they can’t read.

By default, the channels property of a document controls what channels the document is in. If not specified, the document belongs to no channels.

A custom “Sync Function” can customise this behaviour, by assigning channels based other logic, or other properties of a document. Similarly, the Sync Function can apply “write permissions” by rejecting documents based on contents, or user/channel/role access. The default Sync Function allows all writes.

@bbrks Thanks for the suggestion. I have updated the database configuration to include a sync function to set the channel property of all documents to “public”, and grant access to the user “sgwuser2”. Cross check document metadata on server, channel property is set correctly as shown in the image attached:

However, the changes at the server side still do not sync back to couchbase lite client. Cannot see any error message in the log as well, just nothing happens.

Any ideas what’s wrong with my database configuration or replicator configuration?

I can’t see anything wrong with your configuration, can you please upload debug logs collected with sgcollect (SG Collect Info | Couchbase Docs) while you run the replication? (to enable debug logging Logging | Couchbase Docs)