Issue - Not able to filter documents at SyncGateway using SyncGateway JSON configuration
Requirement - I need to pass only those documents which have doc.data.edit = “yes” to the couchbase bucket using import_filter. But the import_filter part is not working and instead, it is sending all those documents which have doc.data.edit = “no” as well.
SyncGateway Version - 2.8.0 (Enterprise Version)
Adding sample document which is added to the couchbase bucket
Import filters are designed to allow documents written in the Couchbase Server bucket to be available to mobile clients, which sounds like the opposite of what you want.
To limit what documents end up in the Couchbase Server bucket, you need to have your sync function reject writes when doc.data.edit === 'no'.
You can use throw() for this, or something more advanced like requireAdmin() depending on use-case.
"sync":
`function (doc) {
if (doc && doc.data && 'edit' in doc.data && doc.data.edit === 'no') {
throw({forbidden: "doc is non-editable!"})
}
}`