File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -142,7 +142,7 @@ async function executeOperationAsync<
142
142
const readPreference = operation . readPreference ?? ReadPreference . primary ;
143
143
const inTransaction = ! ! session ?. inTransaction ( ) ;
144
144
145
- if ( ! readPreference . equals ( ReadPreference . primary ) && inTransaction ) {
145
+ if ( inTransaction && ! readPreference . equals ( ReadPreference . primary ) ) {
146
146
throw new MongoTransactionError (
147
147
`Read preference in a transaction must be primary, not: ${ readPreference . mode } `
148
148
) ;
@@ -169,8 +169,13 @@ async function executeOperationAsync<
169
169
170
170
const server = await topology . selectServerAsync ( selector , { session } ) ;
171
171
172
- if ( session == null || ! operation . hasAspect ( Aspect . RETRYABLE ) ) {
173
- // No session or non-retryable operation, simple early exit
172
+ if ( session == null ) {
173
+ // No session also means it is not retryable, early exit
174
+ return operation . executeAsync ( server , undefined ) ;
175
+ }
176
+
177
+ if ( ! operation . hasAspect ( Aspect . RETRYABLE ) ) {
178
+ // non-retryable operation, early exit
174
179
try {
175
180
return await operation . executeAsync ( server , session ) ;
176
181
} finally {
You can’t perform that action at this time.
0 commit comments