0

I am trying to create a simple console application in .Net(Windows machine) which connects

couchbase lite -> sync-gateway -> couchbase server (hosted in a remote machine).

but the data is not pulled from the server to the lite.

Here is the sample code which I am using -

class Program
{
static void Main(string argss)
{
    // Get the database (and create it if it doesn't exist)
    var database = new Database("testdb");         

    // Create replicator to push and pull changes to and from the cloud
    var targetEndpoint = new URLEndpoint(new Uri("ws://localhost:4984/testdb"));
    var replConfig = new ReplicatorConfiguration(database, targetEndpoint);

    // Add authentication
    replConfig.Authenticator = new BasicAuthenticator("System", "welcome");


    // Create replicator (make sure to add an instance or static variable
    // named _Replicator)
    Replicator _Replicator = new Replicator(replConfig);
    _Replicator.AddChangeListener((sender, args) =>
    {
        if (args.Status.Error != null)
        {
            Console.WriteLine($"Error :: {args.Status.Error}");
        }
    });

    _Replicator.Start();


    // Later, stop and dispose the replicator *before* closing/disposing the database


    using (var query = QueryBuilder.Select(SelectResult.All())
        .From(DataSource.Database(database)))
    {
        // Run the query
        Console.WriteLine($"Query :: {query.ToString()}");
        var result = query.Execute();
        Console.WriteLine($"Result ::  {result.Count()}");
    }
}

below is the config I am using for sync_gateway -

{
"log": ["*"],
"databases": {
"testdb": {
  "server": "http://167.87.206.28:8091",
  "bucket": "Test",
  "username": "System", 
  "password": "welcome", 
  "enable_shared_bucket_access": true, 
  "import_docs": true,
  "num_index_replicas": 0, 
  "users": {
    "GUEST": { "disabled": false, "admin_channels": ["*"] }
  },
  "sync": `function (doc, oldDoc) {
    if (doc.sdk) {
      channel(doc.sdk);
    }
  }`
}
}
}

I am starting the sync_gateway using command -

C:\Program Files\Couchbase\Sync Gateway>sync_gateway.exe ~path\sync-gateway-config.json

when I am trying to run my console application, Data is not pulled from server and getting below errors in console -

enter image description here

not sure what's going wrong. Any leads would be appreciated!

1 Answers1

-1

Add user1 in sg config:

"users": {
    "user1": {"password": "pass", "admin_channels": ["*"]},
    "GUEST": { "disabled": true, "admin_channels": ["*"] }
  }

and

// Add authentication
replConfig.Authenticator = new BasicAuthenticator("user1", "pass");
Sandy
  • 24
  • 2
  • Allowing guest access would allow anyone to login to server. so this solution is nowhere related to what question was asked – Md. Parwez Akhtar May 05 '20 at 07:53
  • @Md.ParwezAkhtar, I just modified the sync gateway config. Now guest is disabled. The point of example showing above is to show you how to add user and password. – Sandy May 06 '20 at 15:24