Is there a way to find out the current cluster name inside of a trigger function? I have a database trigger that updates a field in a document when certain fields are changed in said document - however this is a trigger I would like to deploy across a number of clusters. I can get the current database name from ns in a changeEvent, but I cannot access the cluster name, and I don’t want to have to maintain versions of the code per cluster.
Below is an abridged sample of a function - I can get the dbName, but I cannot get the cluster name - you can see in this example that it is hardcoded to Dev. How do I use the same function code in Dev, Demo, QA etc without hardcoding the cluster name or having to create a new project per cluster so that the cluster name is consistent?
exports = async function (changeEvent) {
const { ns, updateDescription, fullDocument } = changeEvent;
const dbName = ns.db;
// Construct full name from partial names
const { _id, firstName, middleNames, lastName } = fullDocument;
let fullName = (firstName + " " + middleNames + " " + lastName).replace(/\s+/g, ' ').trim()
// Connect to clients collection
const clients = context.services
.get("Dev")
.db(dbName)
.collection("clients");
// Persist to client document
const query = { _id: _id };
const update = {
$set: {
fullname: fullName,
},
};
const options = { upsert: true };
await clients.updateOne(query, update, options);
}