@@ -6,7 +6,6 @@ const Readable = require('stream').Readable;
66const  CoreCursor  =  require ( './cursor' ) ; 
77const  deprecate  =  require ( 'util' ) . deprecate ; 
88const  SUPPORTS  =  require ( './utils' ) . SUPPORTS ; 
9- const  MongoDBNamespace  =  require ( './utils' ) . MongoDBNamespace ; 
109
1110/** 
1211 * @fileOverview  The **AggregationCursor** class is an internal class that embodies an aggregation cursor on MongoDB 
@@ -56,7 +55,7 @@ const MongoDBNamespace = require('./utils').MongoDBNamespace;
5655 * @fires  AggregationCursor#readable 
5756 * @return  {AggregationCursor } an AggregationCursor instance. 
5857 */ 
59- var  AggregationCursor  =  function ( topology ,  ns ,   cmd ,  options )  { 
58+ var  AggregationCursor  =  function ( topology ,  operation ,  options )  { 
6059  CoreCursor . apply ( this ,  Array . prototype . slice . call ( arguments ,  0 ) ) ; 
6160  var  state  =  AggregationCursor . INIT ; 
6261  var  streamOptions  =  { } ; 
@@ -84,9 +83,7 @@ var AggregationCursor = function(topology, ns, cmd, options) {
8483    bson : bson , 
8584    // Namespace 
8685    // TODO: switch to raw namespace object later 
87-     namespace : MongoDBNamespace . fromString ( ns ) , 
88-     // Command 
89-     cmd : cmd , 
86+     namespace : operation . ns , 
9087    // Options 
9188    options : options , 
9289    // Topology 
@@ -149,11 +146,15 @@ if (SUPPORTS.ASYNC_ITERATOR) {
149146 * @return  {AggregationCursor } 
150147 */ 
151148AggregationCursor . prototype . batchSize  =  function ( value )  { 
152-   if  ( this . s . state  ===  AggregationCursor . CLOSED  ||  this . isDead ( ) ) 
149+   if  ( this . s . state  ===  AggregationCursor . CLOSED  ||  this . isDead ( ) )   { 
153150    throw  MongoError . create ( {  message : 'Cursor is closed' ,  driver : true  } ) ; 
154-   if  ( typeof  value  !==  'number' ) 
151+   } 
152+ 
153+   if  ( typeof  value  !==  'number' )  { 
155154    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 ; 
157158  this . setCursorBatchSize ( value ) ; 
158159  return  this ; 
159160} ; 
@@ -165,7 +166,7 @@ AggregationCursor.prototype.batchSize = function(value) {
165166 * @return  {AggregationCursor } 
166167 */ 
167168AggregationCursor . prototype . geoNear  =  deprecate ( function ( document )  { 
168-   this . s . cmd . pipeline . push ( {  $geoNear : document  } ) ; 
169+   this . operation . pipeline . push ( {  $geoNear : document  } ) ; 
169170  return  this ; 
170171} ,  'The `$geoNear` stage is deprecated in MongoDB 4.0, and removed in version 4.2.' ) ; 
171172
@@ -176,7 +177,7 @@ AggregationCursor.prototype.geoNear = deprecate(function(document) {
176177 * @return  {AggregationCursor } 
177178 */ 
178179AggregationCursor . prototype . group  =  function ( document )  { 
179-   this . s . cmd . pipeline . push ( {  $group : document  } ) ; 
180+   this . operation . pipeline . push ( {  $group : document  } ) ; 
180181  return  this ; 
181182} ; 
182183
@@ -187,7 +188,7 @@ AggregationCursor.prototype.group = function(document) {
187188 * @return  {AggregationCursor } 
188189 */ 
189190AggregationCursor . prototype . limit  =  function ( value )  { 
190-   this . s . cmd . pipeline . push ( {  $limit : value  } ) ; 
191+   this . operation . pipeline . push ( {  $limit : value  } ) ; 
191192  return  this ; 
192193} ; 
193194
@@ -198,7 +199,7 @@ AggregationCursor.prototype.limit = function(value) {
198199 * @return  {AggregationCursor } 
199200 */ 
200201AggregationCursor . prototype . match  =  function ( document )  { 
201-   this . s . cmd . pipeline . push ( {  $match : document  } ) ; 
202+   this . operation . pipeline . push ( {  $match : document  } ) ; 
202203  return  this ; 
203204} ; 
204205
@@ -209,9 +210,7 @@ AggregationCursor.prototype.match = function(document) {
209210 * @return  {AggregationCursor } 
210211 */ 
211212AggregationCursor . 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 ; 
215214  return  this ; 
216215} ; 
217216
@@ -222,7 +221,7 @@ AggregationCursor.prototype.maxTimeMS = function(value) {
222221 * @return  {AggregationCursor } 
223222 */ 
224223AggregationCursor . prototype . out  =  function ( destination )  { 
225-   this . s . cmd . pipeline . push ( {  $out : destination  } ) ; 
224+   this . operation . pipeline . push ( {  $out : destination  } ) ; 
226225  return  this ; 
227226} ; 
228227
@@ -233,7 +232,7 @@ AggregationCursor.prototype.out = function(destination) {
233232 * @return  {AggregationCursor } 
234233 */ 
235234AggregationCursor . prototype . project  =  function ( document )  { 
236-   this . s . cmd . pipeline . push ( {  $project : document  } ) ; 
235+   this . operation . pipeline . push ( {  $project : document  } ) ; 
237236  return  this ; 
238237} ; 
239238
@@ -244,7 +243,7 @@ AggregationCursor.prototype.project = function(document) {
244243 * @return  {AggregationCursor } 
245244 */ 
246245AggregationCursor . prototype . lookup  =  function ( document )  { 
247-   this . s . cmd . pipeline . push ( {  $lookup : document  } ) ; 
246+   this . operation . pipeline . push ( {  $lookup : document  } ) ; 
248247  return  this ; 
249248} ; 
250249
@@ -255,7 +254,7 @@ AggregationCursor.prototype.lookup = function(document) {
255254 * @return  {AggregationCursor } 
256255 */ 
257256AggregationCursor . prototype . redact  =  function ( document )  { 
258-   this . s . cmd . pipeline . push ( {  $redact : document  } ) ; 
257+   this . operation . pipeline . push ( {  $redact : document  } ) ; 
259258  return  this ; 
260259} ; 
261260
@@ -266,7 +265,7 @@ AggregationCursor.prototype.redact = function(document) {
266265 * @return  {AggregationCursor } 
267266 */ 
268267AggregationCursor . prototype . skip  =  function ( value )  { 
269-   this . s . cmd . pipeline . push ( {  $skip : value  } ) ; 
268+   this . operation . pipeline . push ( {  $skip : value  } ) ; 
270269  return  this ; 
271270} ; 
272271
@@ -277,7 +276,7 @@ AggregationCursor.prototype.skip = function(value) {
277276 * @return  {AggregationCursor } 
278277 */ 
279278AggregationCursor . prototype . sort  =  function ( document )  { 
280-   this . s . cmd . pipeline . push ( {  $sort : document  } ) ; 
279+   this . operation . pipeline . push ( {  $sort : document  } ) ; 
281280  return  this ; 
282281} ; 
283282
@@ -288,7 +287,7 @@ AggregationCursor.prototype.sort = function(document) {
288287 * @return  {AggregationCursor } 
289288 */ 
290289AggregationCursor . prototype . unwind  =  function ( field )  { 
291-   this . s . cmd . pipeline . push ( {  $unwind : field  } ) ; 
290+   this . operation . pipeline . push ( {  $unwind : field  } ) ; 
292291  return  this ; 
293292} ; 
294293
0 commit comments