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

Method startTransaction

src/sessions.ts:388–422  ·  view source on GitHub ↗

* Starts a new transaction with the given options. * * @remarks * **IMPORTANT**: Running operations in parallel is not supported during a transaction. The use of `Promise.all`, * `Promise.allSettled`, `Promise.race`, etc to parallelize operations inside a transaction is * undefined be

(options?: TransactionOptions)

Source from the content-addressed store, hash-verified

386 * @param options - Options for the transaction
387 */
388 startTransaction(options?: TransactionOptions): void {
389 if (this.snapshotEnabled) {
390 throw new MongoCompatibilityError('Transactions are not supported in snapshot sessions');
391 }
392
393 if (this.inTransaction()) {
394 throw new MongoTransactionError('Transaction already in progress');
395 }
396
397 if (this.isPinned && this.transaction.isCommitted) {
398 this.unpin();
399 }
400
401 this.commitAttempted = false;
402 // increment txnNumber
403 this.incrementTransactionNumber();
404 // create transaction state
405 this.transaction = new Transaction({
406 readConcern:
407 options?.readConcern ??
408 this.defaultTransactionOptions.readConcern ??
409 this.clientOptions?.readConcern,
410 writeConcern:
411 options?.writeConcern ??
412 this.defaultTransactionOptions.writeConcern ??
413 this.clientOptions?.writeConcern,
414 readPreference:
415 options?.readPreference ??
416 this.defaultTransactionOptions.readPreference ??
417 this.clientOptions?.readPreference,
418 maxCommitTimeMS: options?.maxCommitTimeMS ?? this.defaultTransactionOptions.maxCommitTimeMS
419 });
420
421 this.transaction.transition(TxnState.STARTING_TRANSACTION);
422 }
423
424 /**
425 * Commits the currently active transaction in this session.

Callers 15

withTransactionMethod · 0.95
operations.tsFile · 0.80
testFunction · 0.80
crud.prose.test.tsFile · 0.80
updateEmployeeInfoFunction · 0.80
updateEmployeeInfoFunction · 0.80
node_csot.test.tsFile · 0.80

Calls 4

inTransactionMethod · 0.95
unpinMethod · 0.95
transitionMethod · 0.80

Tested by 3

testFunction · 0.64
updateEmployeeInfoFunction · 0.64
updateEmployeeInfoFunction · 0.64