Function: Advanced Sub-Document LOOKUPIN Operation

    March 9, 2025
    + 12

    Perform the Advanced Sub-Document LOOKUPIN operation on a field where Eventing interacts with the Data Service.

    The advancedLookupInField function:

    • Demonstrates the CAS-free Sub-Document LOOKUPIN operation on a document field

    • 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 lookupinfield:

    For more information about the Advanced Sub-Document LOOKUPIN operation, see Sub-Document LOOKUPIN Operation.

    javascript
    // Configure the settings for the advancedLookupInField 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, xattrs) { if (meta.id.startsWith("lookupinfield:") === false) return; var meta = { "id": meta.id }; var res; var opcnt = 1; res = couchbase.lookupIn(src_col, meta, [ couchbase.LookupInSpec.get("<doc_path_0>", {"xattrs": false}), couchbase.LookupInSpec.get("<doc_path_1>") ]); log(opcnt++,res); }