Event function N1QL not working

Check my function code in Event

function OnUpdate(doc, meta) {
    log("Doc created/updated", meta.id);
          var key_id = meta.id;
          var results = SELECT * FROM `traval`.test.test WHERE `id`=$key_id;
          log("results ==", results)
          for (var beer of results) {
          log("Error on OnUpdate request " + err);


Working as expected , no change

Hi @bphalak1,

I am glad this is working for you, however you will perform the same query over and over on every insert or update (as the mutation trigger to the OnUpdate handler).

You probably already know this but I do want to point out if you are listening to travel.test.test the ‘doc’ value already contains what your are using the inline SQL++ or N1QL statement to fetch.

Also a good practice of you are creating toy or test functions would be to limit the triggering documents by doing on

1.Creating another bucket (or keyspace) with one document and listening to that mutation source
2. If you are listening to say traval.test.test try adding a “filter” to your Eventing function like:

function OnUpdate(doc, meta) {
    // filter down to just one document
	if (meta.id !== "__some_key_to_trigger_on__") return;
	* * *


Jon Strabala
Principal Product Manager - Server‌

1 Like