Now the Eventing Function can be pretty simple just create a new object copy what you want and write it back to Couchbase.
function OnUpdate(doc,meta) {
if (doc.type !== "user") return;
var newdoc = {};
// copy the feilds you want
newdoc.type = doc.type;
newdoc.first_name = doc.first_name;
newdoc.last_name = doc.last_name;
newdoc.id = doc.id;
// are you sure you want the home address and the work phone number
newdoc.home = doc.address.home; // just select one
newdoc.phone = doc.phone.work; // just select one
// use a r/w bucket alias named dst_bkt and write
// to another bucket with the same ID
dst_bkt[meta.id] = newdoc;
}
If your version is recent 6.5 or above you can right back to the same bucket and in 7.X to a different or same collection in the same bucket. You might want to either overwrite the document in this case add a processed flag or perhaps change its type.
“dst_bk” is an alias set up in the function’s settings (a bucket binding to an existing bucket or collections) to use as in call an analytics query you would need to use curl() call and it’s REST API we don’t have direct integration like we do for SQK++ (aka N1QL)
Now I’m not sure (I don’t do analytics) but if you just write to a different bucket or collection (the analytics listens too or watches) via the bucket alias I think analytics will just pick up the mutation and then you just do those queries against the data outside of Eventing in Analytics.