@@ -6,7 +6,6 @@ const Readable = require('stream').Readable;
6
6
const CoreCursor = require ( './cursor' ) ;
7
7
const deprecate = require ( 'util' ) . deprecate ;
8
8
const SUPPORTS = require ( './utils' ) . SUPPORTS ;
9
- const MongoDBNamespace = require ( './utils' ) . MongoDBNamespace ;
10
9
11
10
/**
12
11
* @fileOverview The **AggregationCursor** class is an internal class that embodies an aggregation cursor on MongoDB
@@ -56,7 +55,7 @@ const MongoDBNamespace = require('./utils').MongoDBNamespace;
56
55
* @fires AggregationCursor#readable
57
56
* @return {AggregationCursor } an AggregationCursor instance.
58
57
*/
59
- var AggregationCursor = function ( topology , ns , cmd , options ) {
58
+ var AggregationCursor = function ( topology , operation , options ) {
60
59
CoreCursor . apply ( this , Array . prototype . slice . call ( arguments , 0 ) ) ;
61
60
var state = AggregationCursor . INIT ;
62
61
var streamOptions = { } ;
@@ -84,9 +83,7 @@ var AggregationCursor = function(topology, ns, cmd, options) {
84
83
bson : bson ,
85
84
// Namespace
86
85
// TODO: switch to raw namespace object later
87
- namespace : MongoDBNamespace . fromString ( ns ) ,
88
- // Command
89
- cmd : cmd ,
86
+ namespace : operation . ns ,
90
87
// Options
91
88
options : options ,
92
89
// Topology
@@ -149,11 +146,15 @@ if (SUPPORTS.ASYNC_ITERATOR) {
149
146
* @return {AggregationCursor }
150
147
*/
151
148
AggregationCursor . prototype . batchSize = function ( value ) {
152
- if ( this . s . state === AggregationCursor . CLOSED || this . isDead ( ) )
149
+ if ( this . s . state === AggregationCursor . CLOSED || this . isDead ( ) ) {
153
150
throw MongoError . create ( { message : 'Cursor is closed' , driver : true } ) ;
154
- if ( typeof value !== 'number' )
151
+ }
152
+
153
+ if ( typeof value !== 'number' ) {
155
154
throw MongoError . create ( { message : 'batchSize requires an integer' , driver : true } ) ;
156
- if ( this . s . cmd . cursor ) this . s . cmd . cursor . batchSize = value ;
155
+ }
156
+
157
+ this . operation . options . batchSize = value ;
157
158
this . setCursorBatchSize ( value ) ;
158
159
return this ;
159
160
} ;
@@ -165,7 +166,7 @@ AggregationCursor.prototype.batchSize = function(value) {
165
166
* @return {AggregationCursor }
166
167
*/
167
168
AggregationCursor . prototype . geoNear = deprecate ( function ( document ) {
168
- this . s . cmd . pipeline . push ( { $geoNear : document } ) ;
169
+ this . operation . pipeline . push ( { $geoNear : document } ) ;
169
170
return this ;
170
171
} , 'The `$geoNear` stage is deprecated in MongoDB 4.0, and removed in version 4.2.' ) ;
171
172
@@ -176,7 +177,7 @@ AggregationCursor.prototype.geoNear = deprecate(function(document) {
176
177
* @return {AggregationCursor }
177
178
*/
178
179
AggregationCursor . prototype . group = function ( document ) {
179
- this . s . cmd . pipeline . push ( { $group : document } ) ;
180
+ this . operation . pipeline . push ( { $group : document } ) ;
180
181
return this ;
181
182
} ;
182
183
@@ -187,7 +188,7 @@ AggregationCursor.prototype.group = function(document) {
187
188
* @return {AggregationCursor }
188
189
*/
189
190
AggregationCursor . prototype . limit = function ( value ) {
190
- this . s . cmd . pipeline . push ( { $limit : value } ) ;
191
+ this . operation . pipeline . push ( { $limit : value } ) ;
191
192
return this ;
192
193
} ;
193
194
@@ -198,7 +199,7 @@ AggregationCursor.prototype.limit = function(value) {
198
199
* @return {AggregationCursor }
199
200
*/
200
201
AggregationCursor . prototype . match = function ( document ) {
201
- this . s . cmd . pipeline . push ( { $match : document } ) ;
202
+ this . operation . pipeline . push ( { $match : document } ) ;
202
203
return this ;
203
204
} ;
204
205
@@ -209,9 +210,7 @@ AggregationCursor.prototype.match = function(document) {
209
210
* @return {AggregationCursor }
210
211
*/
211
212
AggregationCursor . prototype . maxTimeMS = function ( value ) {
212
- if ( this . s . topology . lastIsMaster ( ) . minWireVersion > 2 ) {
213
- this . s . cmd . maxTimeMS = value ;
214
- }
213
+ this . operation . options . maxTimeMS = value ;
215
214
return this ;
216
215
} ;
217
216
@@ -222,7 +221,7 @@ AggregationCursor.prototype.maxTimeMS = function(value) {
222
221
* @return {AggregationCursor }
223
222
*/
224
223
AggregationCursor . prototype . out = function ( destination ) {
225
- this . s . cmd . pipeline . push ( { $out : destination } ) ;
224
+ this . operation . pipeline . push ( { $out : destination } ) ;
226
225
return this ;
227
226
} ;
228
227
@@ -233,7 +232,7 @@ AggregationCursor.prototype.out = function(destination) {
233
232
* @return {AggregationCursor }
234
233
*/
235
234
AggregationCursor . prototype . project = function ( document ) {
236
- this . s . cmd . pipeline . push ( { $project : document } ) ;
235
+ this . operation . pipeline . push ( { $project : document } ) ;
237
236
return this ;
238
237
} ;
239
238
@@ -244,7 +243,7 @@ AggregationCursor.prototype.project = function(document) {
244
243
* @return {AggregationCursor }
245
244
*/
246
245
AggregationCursor . prototype . lookup = function ( document ) {
247
- this . s . cmd . pipeline . push ( { $lookup : document } ) ;
246
+ this . operation . pipeline . push ( { $lookup : document } ) ;
248
247
return this ;
249
248
} ;
250
249
@@ -255,7 +254,7 @@ AggregationCursor.prototype.lookup = function(document) {
255
254
* @return {AggregationCursor }
256
255
*/
257
256
AggregationCursor . prototype . redact = function ( document ) {
258
- this . s . cmd . pipeline . push ( { $redact : document } ) ;
257
+ this . operation . pipeline . push ( { $redact : document } ) ;
259
258
return this ;
260
259
} ;
261
260
@@ -266,7 +265,7 @@ AggregationCursor.prototype.redact = function(document) {
266
265
* @return {AggregationCursor }
267
266
*/
268
267
AggregationCursor . prototype . skip = function ( value ) {
269
- this . s . cmd . pipeline . push ( { $skip : value } ) ;
268
+ this . operation . pipeline . push ( { $skip : value } ) ;
270
269
return this ;
271
270
} ;
272
271
@@ -277,7 +276,7 @@ AggregationCursor.prototype.skip = function(value) {
277
276
* @return {AggregationCursor }
278
277
*/
279
278
AggregationCursor . prototype . sort = function ( document ) {
280
- this . s . cmd . pipeline . push ( { $sort : document } ) ;
279
+ this . operation . pipeline . push ( { $sort : document } ) ;
281
280
return this ;
282
281
} ;
283
282
@@ -288,7 +287,7 @@ AggregationCursor.prototype.sort = function(document) {
288
287
* @return {AggregationCursor }
289
288
*/
290
289
AggregationCursor . prototype . unwind = function ( field ) {
291
- this . s . cmd . pipeline . push ( { $unwind : field } ) ;
290
+ this . operation . pipeline . push ( { $unwind : field } ) ;
292
291
return this ;
293
292
} ;
294
293
0 commit comments