|
1 | 1 | 'use strict';
|
2 | 2 | const MongoError = require('./error').MongoError;
|
| 3 | +const ReadPreference = require('./topologies/read_preference'); |
| 4 | +const ReadConcern = require('../read_concern'); |
| 5 | +const WriteConcern = require('../write_concern'); |
3 | 6 |
|
4 | 7 | let TxnState;
|
5 | 8 | let stateMachine;
|
@@ -90,18 +93,26 @@ class Transaction {
|
90 | 93 | this.state = TxnState.NO_TRANSACTION;
|
91 | 94 | this.options = {};
|
92 | 95 |
|
93 |
| - if (options.writeConcern || typeof options.w !== 'undefined') { |
94 |
| - const w = options.writeConcern ? options.writeConcern.w : options.w; |
95 |
| - if (w <= 0) { |
| 96 | + const writeConcern = WriteConcern.fromOptions(options); |
| 97 | + if (writeConcern) { |
| 98 | + if (writeConcern.w <= 0) { |
96 | 99 | throw new MongoError('Transactions do not support unacknowledged write concern');
|
97 | 100 | }
|
98 | 101 |
|
99 |
| - this.options.writeConcern = options.writeConcern ? options.writeConcern : { w: options.w }; |
| 102 | + this.options.writeConcern = writeConcern; |
100 | 103 | }
|
101 | 104 |
|
102 |
| - if (options.readConcern) this.options.readConcern = options.readConcern; |
103 |
| - if (options.readPreference) this.options.readPreference = options.readPreference; |
104 |
| - if (options.maxCommitTimeMS) this.options.maxTimeMS = options.maxCommitTimeMS; |
| 105 | + if (options.readConcern) { |
| 106 | + this.options.readConcern = ReadConcern.fromOptions(options); |
| 107 | + } |
| 108 | + |
| 109 | + if (options.readPreference) { |
| 110 | + this.options.readPreference = ReadPreference.fromOptions(options); |
| 111 | + } |
| 112 | + |
| 113 | + if (options.maxCommitTimeMS) { |
| 114 | + this.options.maxTimeMS = options.maxCommitTimeMS; |
| 115 | + } |
105 | 116 |
|
106 | 117 | // TODO: This isn't technically necessary
|
107 | 118 | this._pinnedServer = undefined;
|
|
0 commit comments