applyReadConcern.js 547 B

1234567891011121314151617181920
  1. 'use strict';
  2. module.exports = function applyReadConcern(schema, options) {
  3. if (options.readConcern !== undefined) {
  4. return;
  5. }
  6. // Don't apply default read concern to operations in transactions,
  7. // because you shouldn't set read concern on individual operations
  8. // within a transaction.
  9. // See: https://www.mongodb.com/docs/manual/reference/read-concern/
  10. if (options?.session?.transaction) {
  11. return;
  12. }
  13. const level = schema.options?.readConcern?.level;
  14. if (level != null) {
  15. options.readConcern = { level };
  16. }
  17. };