@@ -38,6 +38,16 @@ class AggregateOperation extends CommandOperationV2 {
38
38
if ( this . hasWriteStage ) {
39
39
this . readPreference = ReadPreference . primary ;
40
40
}
41
+
42
+ if ( options . explain && ( this . readConcern || this . writeConcern ) ) {
43
+ throw new MongoError (
44
+ '"explain" cannot be used on an aggregate call with readConcern/writeConcern'
45
+ ) ;
46
+ }
47
+
48
+ if ( options . cursor != null && typeof options . cursor !== 'object' ) {
49
+ throw new MongoError ( 'cursor options must be an object' ) ;
50
+ }
41
51
}
42
52
43
53
get canRetryRead ( ) {
@@ -52,6 +62,7 @@ class AggregateOperation extends CommandOperationV2 {
52
62
const command = { aggregate : this . target , pipeline : this . pipeline } ;
53
63
54
64
if (
65
+ this . readConcern &&
55
66
( ! this . hasWriteStage || serverWireVersion >= MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT ) &&
56
67
! inTransaction
57
68
) {
@@ -85,29 +96,13 @@ class AggregateOperation extends CommandOperationV2 {
85
96
}
86
97
87
98
if ( options . explain ) {
88
- if ( command . readConcern || command . writeConcern ) {
89
- callback (
90
- new MongoError (
91
- '"explain" cannot be used on an aggregate call with readConcern/writeConcern'
92
- )
93
- ) ;
94
-
95
- return ;
96
- }
97
-
98
99
command . explain = options . explain ;
99
100
}
100
101
101
102
if ( typeof options . comment === 'string' ) {
102
103
command . comment = options . comment ;
103
104
}
104
105
105
- // Validate that cursor options is valid
106
- if ( options . cursor != null && typeof options . cursor !== 'object' ) {
107
- callback ( new MongoError ( 'cursor options must be an object' ) ) ;
108
- return ;
109
- }
110
-
111
106
command . cursor = options . cursor || { } ;
112
107
if ( options . batchSize && ! this . hasWriteStage ) {
113
108
command . cursor . batchSize = options . batchSize ;
0 commit comments