Dynamically changing sync function

Is there a way I can dynamically change sync function for eg. Lets ssy my documents have a field ID and I want to get documents belonging to a particular ID so ID is my variable here. eg. below is a sync function for ID=4

	        function (doc) {
                            channel (doc.channels);
                                   throw({forbidden: "Missing required properties"});

Now This will only work for ID=4. How Can I make my sync function dynamic. Is there a way I can supply arguments to my sync function?


@yagyank.chadha The only arguments available to the sync function are doc and oldDoc. It’s important that the sync function is only based on the content of the document itself, to ensure that the results of the sync function on a given document don’t change if the sync function needs to be rerun.

What’s your specific use case - what type of information are you trying to get into your sync function?

@adamf My use case is like this. I have many documents containing like below

Name : Yagyank
Id : 1
Balance : 20000
Address : xyz

Name : Ricky
Id : 2
Balance : 10000
Address : qwe

This is my doc for Name Yagyank with ID 1 and another doc for Name Ricky and ID 2. Similarly I have 1 million docs for different users. Now my sync gateway should take ID and return only the documents equivalent to that ID. eg If I pass ID=2 so I should only get documents in my couchbaselite of ID 2 from couchbase server via sync gateway