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 withlookupinfield:
For more information about the Advanced Sub-Document LOOKUPIN operation, see Sub-Document LOOKUPIN Operation.
-
advancedLookupInField
-
Input data
-
Output data
// 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);
}
INPUT: KEY lookupinfield:001
{
"id": "lookupinfield:001",
}
2024-03-15T14:42:53.314-07:00 [INFO] 1 {"meta":{"id":"lookupinfield:001","cas":"1710538973313433600"},"success":true}
2024-03-15T14:42:53.316-07:00 [INFO] 2 {"meta":{"id":"lookupinfield:001","cas":"1710538973315596288"},"success":true}
2024-03-15T14:42:53.317-07:00 [INFO] 3 {"meta":{"id":"lookupinfield:001","cas":"1710538973316841472"},"success":true}