@itssrinadh
The Sync Gateway uses a default sync function, which is equivalent to:
function (doc) {
channel(doc.channels);
}
This will tag every document with the channel names that are defined in the documents “channels” property e.g. the following document would be tagged with three channels called “chan1”,“chan2” and “chan3”
{
"channels":["chan1","chan2","chan3"]
}
For a user to receive the document via sync they must have access to one or more of the channels the document is mapped to.
Channel access can be granted to a user via the ADMIN API when creating or updating the user by passing the “admin_channels” property e.g. To give a user access to the “chan1” channel the admin_channels property would be:
"admin_channels":["chan1"]
Users can also be given access to a channel dynamically via the sync function using the ‘access’ method e.g we could change the sync_function to:
function (doc) {
channel(doc.channels);
access(doc.owner, doc.channels);
}
You would change your document to:
{
"owner":"user1"
"channels":["chan4","chan5"]
}
The document would be tagged with the channels “chan4” and “chan5” and ‘user1’ would be given access to channels “chan4” and “chan5”.
When a CBL client authenticates with Sync Gateway as ‘user1’ and initiates a pull replication, the document will be sync’d to the client.
There is an introduction to channels and the sync function here
For a more complete example of a sync function and using channels to partition data between users, take a look at one of the ToDoLite demo projects e.g. Android