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

Function updateSessionFromResponse

src/sessions.ts:1253–1287  ·  view source on GitHub ↗
(session: ClientSession, document: MongoDBResponse)

Source from the content-addressed store, hash-verified

1251}
1252
1253export function updateSessionFromResponse(session: ClientSession, document: MongoDBResponse): void {
1254 if (document.$clusterTime) {
1255 _advanceClusterTime(session, document.$clusterTime);
1256 }
1257
1258 if (document.operationTime && session && session.supports.causalConsistency) {
1259 session.advanceOperationTime(document.operationTime);
1260 }
1261
1262 if (document.recoveryToken && session && session.inTransaction()) {
1263 session.transaction._recoveryToken = document.recoveryToken;
1264 }
1265
1266 if (session?.snapshotEnabled && session.snapshotTime == null) {
1267 // find and aggregate commands return atClusterTime on the cursor
1268 // distinct includes it in the response body
1269 const atClusterTime = document.atClusterTime;
1270 if (atClusterTime) {
1271 session.snapshotTime = atClusterTime;
1272 }
1273 }
1274
1275 if (session.transaction.state === TxnState.STARTING_TRANSACTION) {
1276 if (document.ok === 1) {
1277 session.transaction.transition(TxnState.TRANSACTION_IN_PROGRESS);
1278 } else {
1279 const error = new MongoServerError(document.toObject());
1280 const isRetryableError = error.hasErrorLabel(MongoErrorLabel.RetryableError);
1281
1282 if (!isRetryableError) {
1283 session.transaction.transition(TxnState.TRANSACTION_IN_PROGRESS);
1284 }
1285 }
1286 }
1287}

Callers 1

sendCommandMethod · 0.90

Calls 6

_advanceClusterTimeFunction · 0.90
advanceOperationTimeMethod · 0.80
inTransactionMethod · 0.80
transitionMethod · 0.80
toObjectMethod · 0.45
hasErrorLabelMethod · 0.45

Tested by

no test coverage detected