Function: Basic Bucket Ops


    Goal: Perform the basic bucket operations where Eventing interacts with the Data service.

    • This function basicBucketOps merely demonstrates basic Evening BucketOps.

    • Requires a metadata bucket, a source bucket, and a bucket called "destination".

    • Needs a Binding of type Bucket Alias (as documented in the Scriptlet).

    • Will operate on any mutation where doc.type === "basic_bkt_ops".

    • The final document is deleted, as such the output is the Application log file.

    • For more detail refer to Bucket Accessors

    • basicBucketOps

    • Input Data/Mutation

    • Output Data/Logged

    // To run need a Binding in this Function's Settings as follows:
    // 1. Bucket Alias
    // 2. dst_bkt
    // 3. destination
    // 4. read+write
    function OnUpdate(doc, meta) {
      // filter out non-interesting docs
      if (doc.type !== "basic_bkt_ops") return;
      // Assuming 'dst_bkt' is a bucket alias binding in this case to a non source bucket
      log("OnUpdate got mutation for id",,"doc",doc);
      // make a key based on the of the input mutation
      var dst_key = "dst_" +;
      // make a document to write, include the input mutation's doc
      var doc_to_wr = {"status":3, "mutation": doc};
      // this is a bucket SET operation.
      dst_bkt[dst_key] = doc_to_wr;
      log("wrote DOC to dst_bkt with id",dst_key,doc_to_wr);
      // this is a bucket GET operation.
      var doc_read = dst_bkt[dst_key];
      log("read DOC from dst_bkt with id",dst_key,doc_read);
      // this is a bucket DEL operation.
      delete dst_bkt[dst_key];
      log("deleted "+dst_key+" from dst_bkt");
    INPUT: KEY basic_bkt_ops::1
      "type": "basic_bkt_ops",
      "id": 1,
      "test": true
    2020-08-06T17:16:50.429-07:00 [INFO] "deleted dst_basic_bkt_ops::1 from dst_bkt"
    2020-08-06T17:16:50.428-07:00 [INFO] "read DOC from dst_bkt with id" "dst_basic_bkt_ops::1" {"status":3,"mutation":{"type":"basic_bkt_ops","id":1,"test":true}}
    2020-08-06T17:16:50.427-07:00 [INFO] "wrote DOC to dst_bkt with id" "dst_basic_bkt_ops::1" {"status":3,"mutation":{"type":"basic_bkt_ops","id":1,"test":true}}