applyWriteConcern.js 937 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. const get = require('../get');
  3. module.exports = function applyWriteConcern(schema, options) {
  4. const writeConcern = get(schema, 'options.writeConcern', {});
  5. if (Object.keys(writeConcern).length != 0) {
  6. options.writeConcern = {};
  7. if (!('w' in options) && writeConcern.w != null) {
  8. options.writeConcern.w = writeConcern.w;
  9. }
  10. if (!('j' in options) && writeConcern.j != null) {
  11. options.writeConcern.j = writeConcern.j;
  12. }
  13. if (!('wtimeout' in options) && writeConcern.wtimeout != null) {
  14. options.writeConcern.wtimeout = writeConcern.wtimeout;
  15. }
  16. }
  17. else {
  18. if (!('w' in options) && writeConcern.w != null) {
  19. options.w = writeConcern.w;
  20. }
  21. if (!('j' in options) && writeConcern.j != null) {
  22. options.j = writeConcern.j;
  23. }
  24. if (!('wtimeout' in options) && writeConcern.wtimeout != null) {
  25. options.wtimeout = writeConcern.wtimeout;
  26. }
  27. }
  28. };