how to remove any field from document using eventing on same source bucket.
My task is to remove specific field form all documents in a bucket. (Note: direct N1QL query is not useful as it is taking a lot of time. So thought of eventing but unable to get any solution)
You will need Couchbase 6.5 or later to do this. Let’s say you want to remove field “remove_this” from documents in bucket named “my_bucket”. Here’s how you’d configure the eventing handler:
Source Bucket:
Set source bucket to the bucket of interest, my_bucket
Bindings:
Define this alias in function settings to allow the function to write to the bucket:
AliasName = bkt, Bucket = my_bucket, Access = Read+Write
Function:
function OnUpdate(doc, meta) {
if (doc.removethis) {
delete doc.removethis; // remove the field
bkt[meta.id] = doc; // write it back to the bucket
}
}
If you wish to speed it up, you can add more eventing nodes to the cluster.