Hi Team,
we have create a eventing function between source-data to target-data bucket and we have alias setup as source-data → source and target-data - >target.
we are updating the target document expiry based on some field, for that we have a eventing function below,
var stmt = "UPDATE target-data
USE KEYS “”+docId+
“” SET meta().expiration = " + Math.floor(expiryTime/1000);
log(docId,stmt);
N1QL(stmt);
In this case we are hardcoding the bucket name, is there a way we can get the bucket alias name here?
like,
var stmt = "UPDATE "+**target**+"
USE KEYS “”+docId+
“” SET meta().expiration = " + Math.floor(expiryTime/1000);
log(docId,stmt);
N1QL(stmt);
Thanks.
I tried this option and it doesn’t work for me. I am in 6.6.0 CB version.
Hi @nagarajan_subbaraj
Bucket bindings or aliases can only be used with Basic Bucket Accessors i.e.
https://docs.couchbase.com/server/current/eventing/eventing-language-constructs.html#bucket_accessors
In other words you can manipulate KV directly via an exposed JavaScript MAP my alias below is ‘dest’
function OnUpdate(doc, meta) {
// Assuming 'dest' is a bucket alias binding
var val = dest[meta.id]; // this is a bucket GET operation.
dest[meta.id] = {"status":3}; // this is a bucket SET operation.
delete dest[meta.id]; // this is a bucket DEL operation.
}
However you can not use a Bucket binding alias in a N1QL statement whether inline or via the N1QL() function.
There is currently no way to get the true bucket name from a bucket binding alias, please contact your sales team and have a CBSE (enhancement request) logged -or- contact me via a DM with the name and details of your company.
Best
Jon Strabala
Principal Product Manager - Server