channel()
Assigning Sync Gateway channels
Related Topics: access() | channel() | expiry() | requireAccess() | requireAdmin() | requireRole() | requireUser() | role() | throw()
Arguments
| Argument | Description |
|---|---|
|
Must be a string identifying a channel name, or an array of strings to specify multiple channel names (for example: If the value resolves to null the function result is a no-op. |
Context
The channel function can be called zero or more times from the sync function, for any document.
|
Channels don’t have to be predefined. A channel implicitly comes into existence when a document is routed to it. |
Routing changes have no effect until the document is actually saved in the database, so if the sync function first calls channel() or access(), but then rejects the update, the channel and access changes will not occur.
As a convenience, it is legal to call channel with a null or undefined argument; it simply does nothing.This allows you to do something like channel(doc.channels) without having to first check whether doc.channels exists.
|
Use
This example routes all "published" documents to the "public" channel:
function (doc, oldDoc, meta) {
if (doc.published) {
channel("public");
}
}