N1QL Prepared Statement & Eventing

Can we leverage N1QL prepared statement(“named queries”) in eventing? It can improve performance on static queries.

@househippo - Yes you can. See example below for handler code. You can create the prepare statement before the function is executed using n1ql.

function OnUpdate(doc, meta) {
log(‘document’, doc);
var prepared_result = execute prepared3; // PREPARE prepared3 FROM SELECT count(*) FROM beer-sample;
if(prepared_result[0]["$1"] == 7303){ // beer-sample has 7303 docs.
dst_bucket[meta.id] = doc;
function OnDelete(meta) {

1 Like