-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
filter by channel works with arrays only #1769
Comments
I just tested this against master and filtering by a single channel (not in an array) is working on both the ADMIN API and PUBLIC API. @househippo how are you sending the request, if you are using a cli tool like |
@adamcfraser suggested that the issue is not the filter channels but the doc "channels" property. I have tested and confirmed that the document "channels" property must be an array, a single string value will not map the document to a channel. |
This issue is only occurs when no explicit sync function has been defined the SG config.json. In this case a Javascript interpreter is not used and the doc.channels property is extracted from the document body directly in golang. If the default sync function is explicitly defined in the config.json file then the Javascript interpreter is invoked and the single channel string value is correctly parsed. |
Original: https://forums.couchbase.com/t/sg-filter-by-channel-works-with-arrays-only/8140
Found something interesting that some people might get tripped up on.
I used the default sync function:
function(doc){
channels(doc.channels)
}
I added the below document into SG with "channels":"bob"
{
"_id":"12345",
"channels":"bob"
}
And when I tried to filter by channel via
http://hostname:4984/{db}/_changes?filter=sync_gateway/bychannel&channels=bob
it returned an empty array
When I tried http://hostname:4984/{db}/_changes?filter=sync_gateway/bychannel&channels=*
with a "*" , it worked but I got all the documents in the DB.
But when I changed it to "channels":["bob"] an array everything worked fine 👍 and filters by only docs in the "bob" channel.
{
"_id":"12345",
"channels":["bob"]
}
It accepts one or more arguments, each of which must be a channel name string, or an array of strings.
In the docs when it talks about channels( ) its not that clear about arrays and filter by array only or is that a bug?
Source: http://developer.couchbase.com/documentation/mobile/1.2/develop/guides/sync-gateway/sync-function-api-guide/routing/index.html
The text was updated successfully, but these errors were encountered: