Skip to content
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

Closed
househippo opened this issue May 13, 2016 · 3 comments · Fixed by #1770
Closed

filter by channel works with arrays only #1769

househippo opened this issue May 13, 2016 · 3 comments · Fixed by #1770
Assignees
Labels
Milestone

Comments

@househippo
Copy link

househippo commented May 13, 2016

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

@zgramana zgramana changed the title filter by channel works with arrays only filter by channel works with arrays only May 13, 2016
@zgramana zgramana added this to the 1.3 milestone May 13, 2016
@zgramana zgramana added ready and removed backlog labels May 13, 2016
@ajres
Copy link

ajres commented May 13, 2016

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 curl can you post the full command with quoting and escaping.

@ajres
Copy link

ajres commented May 13, 2016

@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.

@ajres
Copy link

ajres commented May 13, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants