MCPcopy
hub / github.com/mongodb/node-mongodb-native / constructor

Method constructor

src/transactions.ts:85–114  ·  view source on GitHub ↗

Create a transaction

(options?: TransactionOptions)

Source from the content-addressed store, hash-verified

83
84 /** Create a transaction */
85 constructor(options?: TransactionOptions) {
86 options = options ?? {};
87 this.state = TxnState.NO_TRANSACTION;
88 this.options = {};
89
90 const writeConcern = WriteConcern.fromOptions(options);
91 if (writeConcern) {
92 if (writeConcern.w === 0) {
93 throw new MongoTransactionError('Transactions do not support unacknowledged write concern');
94 }
95
96 this.options.writeConcern = writeConcern;
97 }
98
99 if (options.readConcern) {
100 this.options.readConcern = ReadConcern.fromOptions(options);
101 }
102
103 if (options.readPreference) {
104 this.options.readPreference = ReadPreference.fromOptions(options);
105 }
106
107 if (options.maxCommitTimeMS) {
108 this.options.maxTimeMS = options.maxCommitTimeMS;
109 }
110
111 // TODO: This isn't technically necessary
112 this._pinnedServer = undefined;
113 this._recoveryToken = undefined;
114 }
115
116 get server(): Server | undefined {
117 return this._pinnedServer;

Callers

nothing calls this directly

Calls 1

fromOptionsMethod · 0.45

Tested by

no test coverage detected