Not understanding how to get couchbase lite to pull down all exsisting dbs from sync gateway

So I have a Couchbase Sync Gateway with buckets and documents. I am trying to create an app that pulls those buckets and creates couchbase lite db’s out of them. The question that I have is would this be done with syncing or would it be done with a rest api call. If sync how would I do this I see how to create the db from the tutorial but I don’t understand How to pull dbs that are in the sync gateway already. Or do you just create a local db connect it to the syncgateway with a replicator with the url for that specific db and it just pulls down everything for you. i.e.

    // Create Database  
    var database: Database = Database("getting-started", config);

    //  Create replicators to push and pull changes to and from the cloud.
    var targetEndpoint: Endpoint = URLEndpoint(URI("ws://url/SyncGateway/myCloudBucketName"));
    var replConfig: ReplicatorConfiguration = ReplicatorConfiguration(database, targetEndpoint);
    replConfig.replicatorType = ReplicatorConfigurationTypes.replicatorType("Push_And_Pull");


    // Add authentication.
    replConfig.authenticator = BasicAuthenticator("sync-gateway", "password");

    // Create replicator (be sure to hold a reference somewhere that will prevent the Replicator from being GCed)
    var replicator = Replicator(replConfig);



    //Listen to replicator change events.
    replicator.addChangeListener { change: ReplicatorChange ->
        if (change.status.error != null) {
            Log.i("MainActivity", "Error code ::  " + change.status.error.code)
        }
    }

    // Start Replication.
    Log.i("MainActivity", "Starting Replication");
    replicator.start();

sample code of the last idea getting an error code of 5008

 class MainActivity : AppCompatActivity() {
     override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          // Initialize the Couchbase Lite System
               CouchbaseLite.init(applicationContext);

    //Create the database (and create it if it doesn't exist).
    var config: DatabaseConfiguration = DatabaseConfiguration();
    var database: Database = Database("MyDB", config);

    //call initial sync
    try{

        var username: String = "Basic User that you would use";
        var password: String ="Basic Password That You Would Use";


        // Create replicators to push and pull changes to and from the cloud.
        //var targetEndpoint: Endpoint = URLEndpoint(URI("ws://localhost:4984/getting-started-db"));
        var replConfig: ReplicatorConfiguration = ReplicatorConfiguration(database, targetEndpoint);
        replConfig.replicatorType = ReplicatorConfigurationTypes.replicatorType("Pull");
        replConfig.authenticator = BasicAuthenticator(userName,password);
        var replicator = Replicator(replConfig);
        replicator.addChangeListener { change: ReplicatorChange ->
            if (change.status.error != null) {
                Log.i("MainActivity", "Error code ::  " + change.status.error.code)
            }else{
                Log.i("Replicator has synced all the buckets", "Status Code ::  " + change.status.toString())
            }
        }
        // Start Replication.
        Log.i("MainActivity", "Starting Replication");
        replicator.start();
    }catch(error: Exception){
        Log.i("Error", "You have an error")
    }

}

}

Just found out that the 5008 error is TLSCertUntrusted 5008 Cert isn’t trusted for other reason error. Also Discovered it only happens in 2.7.+ of couchbase lite. I have since reverted.

By syncing. Your app shouldn’t have any need to contact Sync Gateway directly; it’s done by Couchbase Lite.

the 5008 error is TLSCertUntrusted 5008 Cert isn’t trusted for other reason error

You shouldn’t be getting any TLS-related errors, since you’re using a ws: URL, not wss:. Also weird that this only happens with 2.7.

You didn’t say what language/platform this is, and I don’t recognize the language, but from the term “Activity” I’m guessing this is Android. @blake.meike, any idea?

Hey jens and @blake.meike I was able to fixed the issue with the TSL error. It was something on my end needed some certificates installed. I am on Android/ kotlin/java. I am a little confused about your answer on the syncing part. What I am trying to do is get couch base lite to sync all the records I have for my buckets connecting through the sync gateway. For some reason I am able to connect but the records aren’t being pulled down. What I was trying to figure out is with an initial sync where you don’t have the db created in cblite already do you just use the same name of the buckets you have on the server then connecting it to that specific buckets url in will pull down the buckets information? so right now I am trying to connect to a bucket call myStuff right cblite connects fine but nun of the records are pulling down as far as I can tell. I know its able to connect because I am not getting any connection failures but I am not sure why the replicator isn’t pulling down the records at all.

Well, its not true that you “don’t have the db created”. In fact , you do have database created locally when you do the following

And you have configured that as your local database endpoint point to in your replicator Configuration in this section of your code

If you confirmed that the connection is established and that there are no errors are reported in Couchbase Lite logs, but your server side documents are not getting synced down then next thing to check would be your sync gateway config and ensure that it is configured correctly per instructions here.

So when you configure the local to the sync-gateway specified db it associates that local db with the one in the server.

Yes, with the sync gateway database (which is backed by server bucket)

So if there are already documents in that server db that aren’t being revised/deleted/created, how does the local db know to pull in all of the server side documents to the local db does Couchbase Lite tell it to do that. if so how is there something I need to do in order to pull down all of the documents. I read that the sync function on the gateway is only called on creation/deletion/updating a document, the document won’t be synced by the sync gateway.

Remember this is the initial sync at the beginning of the application I am trying to get couchbase lite to pull all documents associated with a specific channel. I just looked over our cochbase sync-gateway and I am sure that its configured correctly. our sync function is just the default one right now. Everytime I create a replicator it just opens the connection and has a busy status and then immediately has a stopped status.

You shouldn’t have to do anything special to get the documents. If the replicator is created with ‘pull’ or ‘push/pull’ mode, it will download the docs from SG.

It sounds like you’re trying to filter the replication to a specific channel. Are you certain that the docs in SG are tagged with that channel? What’s the code you’re using to configure the CBL replicator?

A pretty common newbie mistake is not giving your SG user account access to the channels the documents are in. If that happens, no docs get pulled because they’re not accessible to the user. The easiest way to fix this for development purposes is to give the user account access to the "*" channel, which represents all channels.

Ok so I am checking all of the documents have the specified channels that I have created the user api has “admin_channels”: [“channelName”, “all”]}

Hold on wait how do you give the SG access to the channels?

Do you mean the above step in the sync_gateway process?

https://docs.couchbase.com/sync-gateway/2.1/authorizing-users.html#authorizing-users

the user api has “admin_channels”: [“channelName”, “all”]}

So, are your documents assigned to the channels “channelName” and “all”? That is, if you’re using the default sync function, do the documents have properties like e.g. "channels":["channelName"]?

yes their channelName is assigned to the documents as so “channels”: [“channelName”,“all”]

It’s going immediately to Stopped status and not replicating buckets.

Try using the SG REST API to see what the user can see:

curl --user username:password http://sghost:4984/dbname/_all_docs

substitute the right values for username, password, sghost, dbname of course…

so that times out for me when I try to call is this something that has to be configured by us or is it automatically configured by couchbase lite? Secondly is there a way to narrow down the amount of stuff its trying to pull back the amount of data might be a problem.

You did replace sghost with the hostname/address of the machine running Sync Gateway, right? (It should be the same hostname and port as in the URL you use to set up replication in CBL.)