Bucket Name in Eventing

Hi @jon.strabala,
I have an eventing function, where I need to run an N1ql query on different buckets based on the document value.
I was looking through your other answers(Bucket Name from Eventing service) and documentation, where it’s mentioned that we cant use bucket alias in the N1ql query.

But Is it possible to save the bucket name in a variable(tenantId) and use it in the N1Ql query?


var bucektName = doc.tenantId ;

var instanceData = SELECT instance FROM $bucketName  as instance WHERE instance.id = "123"

or anything else could be done here to just make the bucket name dynamic based on the document values??

Thanks,

Hi @Ashish_Mishra

Try something like this ….

// create a N1QL string
var cmd = "SELECT instance FROM " + doc.tenantId + " as instance WHERE instance.id = '123'";

// now create your iterator
var res = N1QL(cmd);

For a full example refer to

https://docs.couchbase.com/server/current/eventing/eventing-handler-basicN1qlPreparedSelectStmt.html

Best

Jon

1 Like