From 7f74e5b1d274587aa241f683166de4b636a26ffc Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Fri, 17 Jul 2026 14:32:42 +0200 Subject: [PATCH] Add support for auxiliary MongoDB sessions in startSession function GitOrigin-RevId: 3ea0acd9c78e837f8aaf7c1e5ac06f7befb80805 --- services/web/app/src/infrastructure/mongodb.mjs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/services/web/app/src/infrastructure/mongodb.mjs b/services/web/app/src/infrastructure/mongodb.mjs index 60cfb376ae..c9c75584e0 100644 --- a/services/web/app/src/infrastructure/mongodb.mjs +++ b/services/web/app/src/infrastructure/mongodb.mjs @@ -160,9 +160,19 @@ export async function waitForDb() { /** * Starts a client session for use with multi-document transactions * (session.withTransaction(...)). Requires Mongo to be running as a replica - * set, which is enforced at startup for every deployment + * set, which is enforced at startup for every deployment. + * + * The session must be started on the same MongoClient as the collections it + * operates on, otherwise Mongo throws "ClientSession must be from the same + * MongoClient". + * + * @param {{ aux?: boolean }} [options] */ -export async function startSession() { +export async function startSession({ aux = false } = {}) { + if (aux && auxMongoClient) { + await auxConnectionPromise + return auxMongoClient.startSession() + } const client = await connectionPromise return client.startSession() }