Hi @vsr1
Is there a way I can add a custom key-value pair to this metadata object?
Thanks
This was answered over on Stack Overflow by @vsr1 (and edited a little myself) - Add a key object to metadata - Couchbase - Stack Overflow
Thanks for the reply,
Let me tell you about our use case, if there is any other soln available.
when a document gets deleted we have written a eventing on delete and want to make a api call. But I need to pass a value which is inside the document to that rest call. Now in on delete function of eventing, we have only access to meta object.
So that’s the reason I am planning to save that custom value in meta and read it in on delete function. Is there any other way to implement this functionality.?
@jon.strabala has expertise on eventing.
Hi @jon.strabala can you help me with this ??
@Ashish_Mishra WRT the Eventing service there are several ideas the come to mind some are trivial and some are complex - the right choice depends on your cluster, the performance you need, and possible other factors.
The most basic is to have a small “proxy” doc as a placeholder for the delete
KEY: proxy:real::1
{
"id": "real::1",
"type": "proxy"
}
which points to the actual doc you want to delete
KEY real::1
{
"id": 1,
"type": "real",
"f1": "yes",
"f2": 1100,
"fn": "n"
}
Then follow the design pattern without N1QL in Cascade Delete | Couchbase Docs and create an Eventing Function that will operate via pure KV:
function OnUpdate(doc, meta) {
// filter out any proxy:: docs, ignore all others
if ((meta.id).startsWith("proxy::") == true) return;
log('OnUpdate notified of insert/update to key', meta.id);
}
function OnDelete(meta, options) {
// only process proxy:: docs, ignore all others
if ((meta.id).startsWith("proxy::") == false) return;
log('A. OnDelete notified of delete of proxy', meta.id);
var real_key = (meta.id).substr(7);
var real_doc = src_bkt[real_key];
if (real_doc) {
delete src_bkt[real_key];
log('B. OnDelete removed the real doc via key',real_key);
log('C. OnDelete do what you want curl, etc. with the real doc',real_doc)
} else {
log('D. OnDelete unexpected no real doc present for key', real_key);
}
}
To run this function “cascadeKvDelete” (works on 6.5.1+):
You should see something like the following in the cascadeKvDelete.log (the UI’s log will be reverse sorted):
2020-12-20T09:24:58.786-08:00 [INFO] "OnUpdate notified of insert/update to key" "real::1"
2020-12-20T09:25:17.420-08:00 [INFO] "A. OnDelete notified of delete of proxy" "proxy::real::1"
2020-12-20T09:25:17.422-08:00 [INFO] "B. OnDelete removed the real doc via key" "real::1"
2020-12-20T09:25:17.422-08:00 [INFO] "C. OnDelete do what you want curl, etc. with the real doc" {"id":1,"type":"real","f1":"yes","f2":1100,"fn":"n"}