Function: Advanced GET operation

    +

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

    • This function advancedGetOp merely demonstrates the Advanced GET operation.

    • Requires a metadata bucket, a source bucket.

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

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

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

    • advancedGetOp

    • Input Data/Mutation

    • Output Data/Logged

    // To run need a Binding in this Function's Settings as follows:
    // 1. Bucket Alias
    // 2. src_bkt
    // 3. source
    // 4. read
    function OnUpdate(doc, meta) {
        // filter out non-intersting documents
        if (!doc.type || doc.type !== "test_adv_get") return;
        log('input doc ', doc);
        log('input meta', meta);
        // let's read the same item and then try to read a non existent item
        var meta_ary = [{"id":"test_adv_get::1"}, {"id":"not_present::1"}];
        for (var i = 0; i < meta_ary.length; i++) {
            var result = couchbase.get(src_bkt,meta_ary[i]);
            if (result.success) {
                log('success adv. get: result',result);
            } else {
                log('failure adv. get: id',meta_ary[i].id,'result',result);
            }
        }
    }
    INPUT: KEY test_adv_get::1
    
    {
        "id": 1,
        "type": "test_adv_get"
    }
    2021-01-07T07:57:24.706-08:00 [INFO] "input doc "
    {
        "id": 1,
        "type": "test_adv_get"
    }
    2021-01-07T07:57:24.706-08:00 [INFO] "input meta"
    {
        "cas": "1610034762747412480",
        "id": "test_adv_get::1",
        "expiration": 0,
        "flags": 33554438,
        "vb": 324,
        "seq": 1
    }
    2021-01-07T07:57:24.707-08:00 [INFO] "success adv. get: result"
    {
        "doc": {
            "id": 1,
            "type": "test_adv_get"
        },
        "meta": {
            "id": "test_adv_get::1",
            "cas": "1610034762747412480",
            "data_type": "json"
        },
        "success": true
    }
    2021-01-07T07:57:24.707-08:00 [INFO] "failure adv. get: id" "not_present::1" "result"
    {
        "error": {
            "code": 272,
            "name": "LCB_KEY_ENOENT",
            "desc": "The document key does not exist on the server",
            "key_not_found": true
        },
        "success": false
    }