I am using Couchbase Lite on Cordova platform and Sync Gateway to sync mobile device data to Couchbase Server, I can make the push replication work, but there are different types of docs in one mobile Couchbase lite database, and I only want to push part of docs to the server.
When user pull some docs to mobile devices, I also want to avoid user to push those docs changes back to the server (single direction replication from server to mobile client).
I searched the forum and know there are methods in ios and android native way by defining and specify a filter, but I can not figure how to define a filter in couchbase lite and specify filter params with RESTful api.
On iOS you can define a filter function in a design document, as documented here. That page only talks about using filters for the changes feed, but you can also set a filter on a push replication.
That feature’s not implemented yet on Android, but I think it’s being added soon.
by_uid: function (doc, req) {
if (!req) {
return true;
}
return doc.t === 'P' && doc.u === req.query.uid;
}.toString()
Then set filter name and query_params to the sync request, when start sync, there are warnings:
*** WARNING: JS function threw exception: TypeError: undefined is not an object (evaluating ‘a.query.uid’)
I tried several times and found out the second parameter seems is just the query part. so I changed the filter to:
by_uid: function (doc, req) {
if (!req) {
return true;
}
return doc.t === 'P' && doc.u === req.uid;
}.toString()
Now it works, not sure if it really works as designed?
Hi @Nithin,
I check our source codes, but I am not sure why the javascript filter does not work with this case. Can you file the ticket for this problem?
Thanks!