Function: Advanced TOUCH Operation

      +

      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.

      • advancedTouchOp

      • Input Data

      • Output Data

      // 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);
          }
      }
      INPUT: KEY ten_seconds:001
      
      {
          "id": "ten_seconds:001",
          "type": "Auto-deletes in 10 seconds. Keep refreshing to retrieve documents."
      }
      2024-03-15T11:57:51.103-07:00 [INFO] "input doc"
      {
        "id": "ten_seconds:001",
        "type": "Auto-deletes in 10 seconds. Keep refreshing to retrieve documents."
      }
      
      2024-03-15T11:57:51.103-07:00 [INFO] "input meta"
      {
        "cas": "1710529071079817216",
        "id": "ten_seconds:001",
        "expiration": 0,
        "flags": 33554438,
        "vb": 679,
        "seq": 102,
        "datatype": "json",
        "keyspace":
        {
          "bucket_name": "travel-sample",
          "scope_name": "tenant_agent_00",
          "collection_name": "bookings"
        },
        "cid": 18
      }
      
      2024-03-15T11:57:51.108-07:00 [INFO] "success adv. touch: result"
      {
        "meta":
        {
          "id": "ten_seconds:001",
          "cas": "1710529071107276800"
        },
        "success": true
      }
      
      2024-03-15T11:58:03.302-07:00 [INFO] "Doc deleted/expired" "ten_seconds:001"
      {
        "expired": true
      }