When a user adds a new channel, I stop the replication, and create a new replication object. I have also tried, just stopping it, adding the channel, and starting the replication again. But that had similar issues.
I wonder if my issue is anything to do with how I am doing user management (or not doing user management). I currently have a single user, that I’ve hard-coded into my app. I am using channels to decide which “libraries” of data is synced. To add a new “library”, the user adds the api key (which is actually the channel name). This way, I’m intending for multiple users to be able to sync the same library if they have the api key.
When I start a replication, a message such as “Puller: starting ChangeTracker with since=25018
” is shown to the console. So, I wonder if it’s just not syncing data before that version, because other client (with the same username) has already pulled those versions? However, the doc’s lead me to believe that I can add and remove channels as I like, and it should all just work.
Anyway, here is my replication code:
My C# code for Initial replication:
var database = Manager.SharedInstance.GetDatabase ("mydb");
var channels = new List<string>();
// I have a utility function for fetching channels, but it's effectively the same as:
channels.Add("channel1");
channels.Add("channel2");
Replication pull = null;
if (channels.Count > 0) {
var url = new Uri ("https://mydomain.com/mydb_sync_gateway");
// Same username & password for all users. Could this be my problem?
var auth = AuthenticatorFactory.CreateBasicAuthenticator ("username", "password");
var pull = database.CreatePullReplication (url);
pull.Authenticator = auth;
pull.Continuous = true;
pull.Channels = channels;
pull.Start ();
}
Once a user has added a channel, I’m restarting my replication like this:
channels.Add("channel3");
if (pull != null)
pull.Stop ();
if (channels.Count > 0) {
var url = new Uri ("https://mydomain.com/mydb_sync_gateway");
var auth = AuthenticatorFactory.CreateBasicAuthenticator ("username", "password");
var pull = database.CreatePullReplication (url);
pull.Authenticator = auth;
pull.Continuous = true;
pull.Channels = channels;
pull.Start ();
}