Multiple clients couchbase lite to server replication


I’m very new to mobile dev and couchbase. I’m moving my first steps with Xamarin Mobile Lite and trying to understand how to create an App that handles multiple clients. Each client will have it’s own set of documents/data but I would run a single couchbase instance.

So I’m wondering what is the best practise for doing this:

  • Set filters on local database and replicator to filter by client id (here is a topic showing something similar I need Couchbase Lite to CouchDB Replication
  • Create different buckets on couchbase server and somehow (I don’t know yet!) let gateway sync client data to the right bucket based on authentication or something
  • Any other way?

Any help/suggestion is very appreciated,


The Couchbase sync gateway lets you assign documents of one bucket to “channels”: all documents of a channel are replicated to all clients listening to / granted access to this channel.
This is done within the sync function :
In your case, if documents are not shared between users, you can use the client id as a channel name for example.

Wow… this could be of course one good solution!

In my undestanding (…which is unstable right now due to a lot of new information I’m facing to) I need to:

  1. Set the Gateway sync funtion to: function (doc) { channel(; }
  2. Each document on mobile database need to have a property called “channel” which value is the client id
  3. Need to set user roles to authorize users to them channel(s)

Am I missing something?


that’s it.

Your sync function could look something like

  var channelName = doc.clientId;
  channel(channelName); // assign the document to the channel
  access(doc.clientId, channelName); //grant the user access to the channel