Thank you VERY MUCH for your answer !!!
I tried following syntax :
try {
// Get the target service and database info
// TARGET_CLUSTER_NAME is defined in values, and returns exact datasource name
const serviceName = context.values.get("PAX_TARGET_CLUSTER");
const database = "pax";
// Get service from context
const targetsn = context.services.get(serviceName);
console.log(`Target SN: ${JSON.stringify(targetsn, null, 2)}`);
// Get db connection
const targetdb = targetsn.db(database);
console.log(`Target DB: ${JSON.stringify(targetdb, null, 2)}`);
// Actually perform a mongo action
// changeEvent being the payload the function receives as an argument :
await targetdb.dropCollection(changeEvent.ns.coll);
} catch(err) {
console.log("Error performing MongoDB operation:", err.message);
}
And then output is :
Target SN: {
“version”: 1
}
Target DB: {}
Error performing MongoDB operation: ‘dropCollection’ is not a function
Indeed, context.services.get(serviceName) is {}