Function: Advanced TOUCH Operation

    March 16, 2025
    + 12

    Perform the Advanced TOUCH operation where Eventing interacts with the Data Service.

    The advancedTouchOp function:

    • Performs the Advanced TOUCH operation

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

    • Requires a binding of type bucket alias

    • Operates on any mutation where the meta.id or KEY starts with ten_seconds:

    • Does not require that you send the document back to the Data Service to update the TTL

    For more information about the Advanced TOUCH operation, see Advanced TOUCH Operation.

    javascript
    // Configure the settings for the advancedTouchOp function as follows: // // Version 7.6+ // "Function Scope" // *.* (or try bulk.data if non-privileged) // "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" function OnUpdate(doc, meta) { if (! meta.id.startsWith("ten_seconds:") ) return; log('input meta', meta); log('input doc', doc); var expiry = new Date(); expiry.setSeconds(expiry.getSeconds() + 10); var req = {"id": meta.id, "expiry_date": expiry}; var result = couchbase.touch(src_col, req); if (result.success) { log('success adv. touch: result', result); } else { log('failure adv. touch: id', req.id, 'result', result); } }