From 0596f558bf444eab48ca0fb232ac43794a69e9c2 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Wed, 8 May 2024 15:05:30 -0400 Subject: [PATCH] fix: add missing file --- lib/helpers/schema/applyReadConcern.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lib/helpers/schema/applyReadConcern.js diff --git a/lib/helpers/schema/applyReadConcern.js b/lib/helpers/schema/applyReadConcern.js new file mode 100644 index 00000000000..80d4da6eb20 --- /dev/null +++ b/lib/helpers/schema/applyReadConcern.js @@ -0,0 +1,22 @@ +'use strict'; + +const get = require('../get'); + +module.exports = function applyReadConcern(schema, options) { + if (options.readConcern !== undefined) { + return; + } + + // Don't apply default read concern to operations in transactions, + // because you shouldn't set read concern on individual operations + // within a transaction. + // See: https://www.mongodb.com/docs/manual/reference/read-concern/ + if (options && options.session && options.session.transaction) { + return; + } + + const level = get(schema, 'options.readConcern.level', null); + if (level != null) { + options.readConcern = { level }; + } +};