A newer version of this documentation is available.

View Latest

Function: Advanced INCREMENT operation

    March 9, 2025
    + 12

    Goal: Perform the Advanced INCREMENT operation where Eventing interacts with the Data service.

    • This function advancedIncrementOp merely demonstrates the Advanced INCREMENT operation.

    • Requires Eventing Storage (or metadata collection) and a "source" collection.

    • Needs a Binding of type "bucket alias" (as documented in the Scriptlet).

    • Will operate on any mutation and count the mutations subject to DCP dedup.

    • For more information refer to Advanced INCREMENT operation in the detailed documentation.

    javascript
    // To run configure the settings for this Function, advancedIncrementOp, as follows: // // Version 7.1+ // "Function Scope" // *.* (or try bulk.data if non-privileged) // Version 7.0+ // "Listen to Location" // bulk.data.source // "Eventing Storage" // rr100.eventing.metadata // Binding(s) // 1. "binding type", "alias name...", "bucket.scope.collection", "Access" // "bucket alias", "src_col", "bulk.data.source", "read and write" // // Version 6.6.1 // "Source Bucket" // source // "MetaData Bucket" // metadata // Binding(s) // 1. "binding type", "alias name...", "bucket", "Access" // "bucket alias", "src_col", "source", "read and write" function OnUpdate(doc, meta) { if (!meta.id.startsWith("inc:")) return; // log('input meta', meta); // log('input doc ', doc); // if doc.count doesn't exist it will be created var ctr_meta = {"id": "my_atomic_counter:1" }; var result = couchbase.increment(src_col,ctr_meta); if (result.success) { log('success adv. increment: result',result); } else { log('failure adv. increment: id',ctr_meta.id,'result',result); } }