Eventing onUpdate processes all data in the bucket


#1

I am trying to use Eventing for calculating some stats. The scenario is the following:

  1. Save raw data in Bucket_1. Bucket_1 contains documents for multiple customers.
  2. OnUpdate function in Eventing kick in.
  3. Calculation in OnUpdate function should only calculate and update data for the customer that we saved in Step 1, thus processing only part of the bucket content.
  4. Save calculated stats in Bucket_2.

While debugging, I deleted the all the content (calculated stats) in Bucket_2., and noticed that when I added new document for customer in Bucket_1, I get in results Bucket_2 calculated stats for all existing customers from Bucket_1.
Tested this several times: by not deleting all results documents in Bucket_2 and added timestamps within results document to trace are they are all being updated on update of 1 document. Every time Update function kicks in for 1 customer, all customers results stats docs get new timestamp as well.

Questions:

  1. Is it expected behavior for Update Eventing function when all docs get reprocessed.
  2. If it is expected is there way to limit the processing of the documents only for the customer that is being added/updated.

Thank you


#2

Hi evgeniya.bell,

This is not expected. The OnUpdate function will run only for the document that changed. The document is passed as the parameter to the OnUpdate call. You can do a log(doc); to have it written to the application log file to verify this is indeed the case.

Only when you deploy a function, you can choose to have it run against all documents in the bucket (“From Beginning”) or on changes that happen after deployment completes (“From Now”). After deployment, there is no control over this, only documents that change will trigger OnUpdate function.

If you share the handler definition and some sample data and expected output, I can review to see why it may not be doing what is desired.

Thank you,
Siri