File tree Expand file tree Collapse file tree 7 files changed +27
-37
lines changed
connection-monitoring-and-pooling Expand file tree Collapse file tree 7 files changed +27
-37
lines changed Original file line number Diff line number Diff line change @@ -81,7 +81,6 @@ export interface CommandOptions extends BSONSerializeOptions {
81
81
/** Session to use for the operation */
82
82
session ?: ClientSession ;
83
83
documentsReturnedIn ?: string ;
84
- noResponse ?: boolean ;
85
84
omitReadPreference ?: boolean ;
86
85
87
86
// TODO(NODE-2802): Currently the CommandOptions take a property willRetryWrite which is a hint
@@ -94,6 +93,9 @@ export interface CommandOptions extends BSONSerializeOptions {
94
93
writeConcern ?: WriteConcern ;
95
94
96
95
directConnection ?: boolean ;
96
+
97
+ // Triggers fire-and-forget protocol for commands that don't support WriteConcern
98
+ moreToCome ?: boolean ;
97
99
}
98
100
99
101
/** @public */
@@ -439,7 +441,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
439
441
zlibCompressionLevel : this . description . zlibCompressionLevel
440
442
} ) ;
441
443
442
- if ( options . noResponse || message . moreToCome ) {
444
+ if ( message . moreToCome ) {
443
445
yield MongoDBResponse . empty ;
444
446
return ;
445
447
}
@@ -527,11 +529,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
527
529
new CommandSucceededEvent (
528
530
this ,
529
531
message ,
530
- options . noResponse
531
- ? undefined
532
- : message . moreToCome
533
- ? { ok : 1 }
534
- : ( object ??= document . toObject ( bsonOptions ) ) ,
532
+ message . moreToCome ? { ok : 1 } : ( object ??= document . toObject ( bsonOptions ) ) ,
535
533
started ,
536
534
this . description . serverConnectionId
537
535
)
Original file line number Diff line number Diff line change @@ -628,7 +628,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
628
628
this ,
629
629
new RunAdminCommandOperation (
630
630
{ endSessions } ,
631
- { readPreference : ReadPreference . primaryPreferred , noResponse : true }
631
+ { readPreference : ReadPreference . primaryPreferred , moreToCome : true }
632
632
)
633
633
) ;
634
634
} catch ( error ) {
Original file line number Diff line number Diff line change @@ -55,7 +55,6 @@ export interface CommandOperationOptions
55
55
// Admin command overrides.
56
56
dbName ?: string ;
57
57
authdb ?: string ;
58
- noResponse ?: boolean ;
59
58
}
60
59
61
60
/** @internal */
Original file line number Diff line number Diff line change @@ -5,8 +5,9 @@ import { type TODO_NODE_3286 } from '../mongo_types';
5
5
import type { ReadPreferenceLike } from '../read_preference' ;
6
6
import type { Server } from '../sdam/server' ;
7
7
import type { ClientSession } from '../sessions' ;
8
+ import type { WriteConcern } from '../write_concern' ;
8
9
import { MongoDBNamespace } from '../utils' ;
9
- import { AbstractOperation } from './operation' ;
10
+ import { Aspect , defineAspects , AbstractOperation } from './operation' ;
10
11
11
12
/** @public */
12
13
export type RunCommandOptions = {
@@ -51,7 +52,7 @@ export class RunAdminCommandOperation<T = Document> extends AbstractOperation<T>
51
52
constructor (
52
53
public command : Document ,
53
54
public override options : RunCommandOptions & {
54
- noResponse ?: boolean ;
55
+ moreToCome ?: boolean ;
55
56
bypassPinningCheck ?: boolean ;
56
57
}
57
58
) {
@@ -72,4 +73,4 @@ export class RunAdminCommandOperation<T = Document> extends AbstractOperation<T>
72
73
} ) ;
73
74
return res ;
74
75
}
75
- }
76
+ }
Original file line number Diff line number Diff line change @@ -144,6 +144,21 @@ describe('Connection', function () {
144
144
}
145
145
}
146
146
} ) ;
147
+
148
+ it ( 'supports fire-and-forget messages' , async function ( ) {
149
+ const options : ConnectionOptions = {
150
+ ...commonConnectOptions ,
151
+ connectionType : Connection ,
152
+ ...this . configuration . options ,
153
+ metadata : makeClientMetadata ( { driverInfo : { } } ) ,
154
+ extendedMetadata : addContainerMetadata ( makeClientMetadata ( { driverInfo : { } } ) )
155
+ } ;
156
+
157
+ const conn = await connect ( options ) ;
158
+ const readSpy = sinon . spy ( conn , 'readMany' ) ;
159
+ await conn . command ( ns ( '$admin.cmd' ) , { ping : 1 } , { moreToCome : true } ) ;
160
+ expect ( readSpy ) . to . not . have . been . called ;
161
+ } ) ;
147
162
} ) ;
148
163
149
164
describe ( 'Connection - functional' , function ( ) {
Original file line number Diff line number Diff line change @@ -682,7 +682,7 @@ describe('class MongoClient', function () {
682
682
expect ( result2 ) . to . have . property ( 'ok' , 1 ) ;
683
683
} ) ;
684
684
685
- it ( 'sends endSessions with noResponse set' , async ( ) => {
685
+ it ( 'sends endSessions with writeConcern w = 0 set' , async ( ) => {
686
686
const session = client . startSession ( ) ; // make a session to be ended
687
687
await client . db ( 'test' ) . command ( { ping : 1 } , { session } ) ;
688
688
await session . endSession ( ) ;
@@ -698,7 +698,7 @@ describe('class MongoClient', function () {
698
698
expect ( startedEvents ) . to . have . lengthOf ( 1 ) ;
699
699
expect ( startedEvents [ 0 ] ) . to . have . property ( 'commandName' , 'endSessions' ) ;
700
700
expect ( endEvents ) . to . have . lengthOf ( 1 ) ;
701
- expect ( endEvents [ 0 ] ) . to . have . property ( ' reply' , undefined ) ; // noReponse: true
701
+ expect ( endEvents [ 0 ] ) . to . containSubset ( { reply : { ok : 1 } } ) ; // writeConcern.w = 0
702
702
} ) ;
703
703
704
704
context ( 'when server selection would return no servers' , ( ) => {
Original file line number Diff line number Diff line change @@ -28,29 +28,6 @@ describe('new Connection()', function () {
28
28
29
29
before ( ( ) => mock . createServer ( ) . then ( s => ( server = s ) ) ) ;
30
30
31
- it ( 'supports fire-and-forget messages' , async function ( ) {
32
- server . setMessageHandler ( request => {
33
- const doc = request . document ;
34
- if ( isHello ( doc ) ) {
35
- request . reply ( mock . HELLO ) ;
36
- }
37
-
38
- // black hole all other requests
39
- } ) ;
40
-
41
- const options = {
42
- ...connectionOptionsDefaults ,
43
- connectionType : Connection ,
44
- hostAddress : server . hostAddress ( ) ,
45
- authProviders : new MongoClientAuthProviders ( )
46
- } ;
47
-
48
- const conn = await connect ( options ) ;
49
- const readSpy = sinon . spy ( conn , 'readMany' ) ;
50
- await conn . command ( ns ( '$admin.cmd' ) , { ping : 1 } , { noResponse : true } ) ;
51
- expect ( readSpy ) . to . not . have . been . called ;
52
- } ) ;
53
-
54
31
it ( 'destroys streams which time out' , async function ( ) {
55
32
server . setMessageHandler ( request => {
56
33
const doc = request . document ;
You can’t perform that action at this time.
0 commit comments