Filter replication on channels using cordova and sync gateway


#1

Hello out there,

I’m having trouble wrapping my head arround an error I’m encountering, while trying to filter a repilcation using specific channels.

For my ionic/cordova application I want to connect to a Sync Gateway but limit the replication to specific channels. The public channel ("!") and one specific user channel (“user_user_1”) to be precise.

I think I have set up the replication as described in this post: How to sync a specific channel with ionic2, couchbase lite 2.0 and sync gateway 1.5

So what I do, is opening a XMLHttpRequest, which looks like this

Sending database request to 
|http://0b67b067-01d1-4056-833c-459167626dd4:9af95e01-c7f9-462a-bb3e-d4cd300ab79e@localhost:5984/_replicate?|
with data
|{
    "source": "http://client13:4984/db",
    "target": "db",
    "continuous": true,
    "filter": "sync_gateway/bychannel",
    "channels": "user_user_1"
}|

The local server acknowledges this with

Established sync. Response |{"session_id":"repl002","ok":true}|

And the summary of active tasks includes the replication:

{
    "completed_change_count": 0,
    "source": "http://client13:4984/db",
    "task": "repl001",
    "status": "Processed 0 / 0 changes",
    "progress": 0,
    "continuous": true,
    "target": "db",
    "change_count": 0,
    "type": "Replication"
}

However the replications fails due to an error 400

ChangeTracker{http://client13:4984/db, OneShot, @b7f03fd}: Change tracker got error 400

while the logs of the sync gateway show the following error:

2018-04-09T12:30:12.212Z HTTP:  #1241: POST /db/_changes?feed=normal&heartbeat=30000&style=all_docs&filter=sync_gateway%2Fbychannel
2018-04-09T12:30:12.213Z Changes+: Changes POST request.  URL: /db/_changes?feed=normal&heartbeat=30000&style=all_docs&filter=sync_gateway%2Fbychannel, feed: normal, options: {Since:0 Limit:0 Conflicts:true IncludeDocs:false Wait:false Continuous:false Terminator:<nil> HeartbeatMs:30000 TimeoutMs:300000 ActiveOnly:false}, filter: sync_gateway/bychannel, bychannel: [], docIds: []
2018-04-09T12:30:12.213Z HTTP: #1241:     --> 400 Missing 'channels' filter parameter  (0.6 ms)

This indicates that the local couchbase lite instance on the mobile does not include the channels parameter in the POST request to the sync gateway although it is specified in the initial request issued by may application.

The manual request using curl deliverst the expected result:

curl -X POST "http://localhost:4984/db/_changes" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"limit\": 0, \"style\": \"all_docs\", \"active_only\": false, \"include_docs\": false, \"filter\": \"sync_gateway/bychannel\", \"channels\": \"user_user_1\", \"feed\": \"normal\", \"since\": 0, \"heartbeat\": 30000, \"timeout\": 30000}"

Can anyone of you help me to determine the mistake I made? It seems as if the couchbase lite instance just ignores my specified channels

Thank you very much in advance!


#2

Which versions are you using?

Also, it looks like it dropped your "continuous": true setting. This seems very odd.

The task in the Established response you posted is different from the task in the summary. Any chance there was a misread of something?


#3

Thanks for your reply. I am using CBLite 1.4.1 and SyncGateway 1.5.

Moreover I solved the problem yesterday late in the evening. Found that I misread the docs and was mislead by a wrong (or possibly outdated) information in the thread linked above.

In this thread it was stated that the channels parameter should be specified alongside the filter parameter. However the docs for CBLite 1.4 say that it must be wrapped into a query_params object.
As a result the correct POST request should look like this:

{
    "source": "http://client13:4984/db",
    "target": "db",
    "continuous": true,
    "filter": "sync_gateway/bychannel",
    "query_params": {
        "channels": "user_user_1"
    }
}