Hi, I am using sg 2.6 with couchbase server 6.0.2. I have a requirement where I need to assign channels to documents in a bucket based on lookup data stored somewhere (perhaps docs in the same source bucket with a different type). In the Sync Function, I want to be able to write a N1QL query or any other mechanism (rest apis?) to do a lookup on the reference data using an attribute in my current document (which invoked the sync function) and assign channel based on the looked up value. I do not want to hardcode channel assignment in the sync function. I cant seem to find a way to write a N1QL in sync function or access data from another unrelated document. Any thoughts or suggestions? Thanks
You cannot do that from the Sync Function .
Why don’t you include the look up value within the document thats being routed ? It would be more efficient than doing a lookup. Besides, if channel assignments are done based on an external attribute, you would have to figure out a way to update channel assignments, for instance if that attribute value changes.
Channel assignments done from within the sync function are dynamic and done at the time the mutation is processed. You are not hardcoding them.
If you absolutely must keep that look up value separately, then you can consider using our eventing service for updating the channels property in the document 9and sync function assigns documents based on channels property) …but I think reconsidering the data model would be simpler.