The content of this article applies to Couchbase Server 7.X and above.
Summary:
Couchbase N1QL service limits the ability to run a simple query to retrieve the keys of binary documents.
To tackle this, the article provides an easier way to retrieve all the binary document keys of a specific scope and collection using the Couchbase Eventing Service.
Pre-requisites:
- One or more eventing service nodes.
- Couchbase Server version 7.x and above.
- One separate scope and collection for the eventing service metadata.
- One collection in which the result will be stored.
Steps:
1. Add a separate scope (i.e "meta_scope") and collection (i.e "meta_coll") for the eventing service metadata
2. "src_coll" is the collection to which the eventing service would listen and "result_coll" is the collection to which the results will be stored (i.e the keys of the binary documents in "src_coll" will be stored in "result_coll")
3. Create an eventing function with the below settings where the Deployment Feed Boundary can be set to the desired setting based on the use-case (Make sure the Access is set to "Read and Write")
4. Create and save the below eventing javascript function code that extracts the keys of binary documents
function OnUpdate(doc, meta) {
if (meta.datatype == "binary") {
log("Binary document received with id: ", meta.id);
destination[meta.id] = "";
}
log("Received non-binary document with id: ", meta.id);
}
function OnDelete(meta, options) {}
Result
After deploying the eventing function, the keys of the binary documents will be stored in the "result_coll" collection.
Comments
0 comments
Please sign in to leave a comment.