Couchbase Eventing Function not working

I wrote a simple couchbase function
function onUpdate{
doc[“Hi”] = “Hello”;
}
Just trying to add afield in my document on every mutation. But it is not reflecting in the document after deployed function starts running. Please suggest.

Hey vishal00921,
Do you have a mapping for destination bucket “doc”? It will be great if you export your function and share with us.

Yes, the format of the handler is as follows:

function OnUpdate(doc, meta) {
   doc['Hi'] = 'Hello';
   dst_bucket[meta.id] = doc;
}

A few notes:

  1. The handler signature is OnUpdate(doc, meta)
  2. meta.id is the key of the document that was just changed
  3. When you do doc[‘Hi’] you’re accessing a field by name ‘Hi’ inside the JSON object doc
  4. Assuming dst_bucket is mapped to a Couchbase bucket in “Bindings” area of the handler, assigning to this object will write to the mapped bucket, dst_bucket
  5. In 6.0 you cannot modify the source bucket that triggered the handler (to avoid recursion). You must make a copy of the modified document to a different bucket. [This restriction is relaxed in 6.5 which has automatic recursion detection & suppression. If you want an early build to try, let me know]

Best,
Siri