@@ -113,6 +113,13 @@ function Cursor(topology, ns, cmd, options) {
113
113
const bson = topology . s . bson ;
114
114
const topologyOptions = topology . s . options ;
115
115
116
+ if ( typeof ns !== 'string' ) {
117
+ this . operation = ns ;
118
+ ns = this . operation . ns . toString ( ) ;
119
+ options = this . operation . options ;
120
+ cmd = { } ;
121
+ }
122
+
116
123
// Tailable cursor options
117
124
const numberOfRetries = options . numberOfRetries || 5 ;
118
125
const tailableRetryInterval = options . tailableRetryInterval || 500 ;
@@ -168,12 +175,14 @@ function Cursor(topology, ns, cmd, options) {
168
175
this . sortValue = this . s . cmd . sort ;
169
176
170
177
// Get the batchSize
171
- const batchSize =
172
- cmd . cursor && cmd . cursor . batchSize
173
- ? cmd . cursor && cmd . cursor . batchSize
174
- : options . cursor && options . cursor . batchSize
175
- ? options . cursor . batchSize
176
- : 1000 ;
178
+ let batchSize = 1000 ;
179
+ if ( cmd . cursor && cmd . cursor . batchSize ) {
180
+ batchSize = cmd . cursor && cmd . cursor . batchSize ;
181
+ } else if ( options . cursor && options . cursor . batchSize ) {
182
+ batchSize = options . cursor . batchSize ;
183
+ } else if ( typeof options . batchSize === 'number' ) {
184
+ batchSize = options . batchSize ;
185
+ }
177
186
178
187
// Set the batchSize
179
188
this . setCursorBatchSize ( batchSize ) ;
@@ -224,10 +233,19 @@ for (let name in CoreCursor.prototype) {
224
233
}
225
234
226
235
Cursor . prototype . _initializeCursor = function ( callback ) {
227
- // implicitly create a session if one has not been provided
228
- if ( ! this . s . explicitlyIgnoreSession && ! this . s . session && this . s . topology . hasSessionSupport ( ) ) {
229
- this . s . session = this . s . topology . startSession ( { owner : this } ) ;
230
- this . cursorState . session = this . s . session ;
236
+ if ( this . operation && this . operation . session != null ) {
237
+ this . s . session = this . operation . session ;
238
+ this . cursorState . session = this . operation . session ;
239
+ } else {
240
+ // implicitly create a session if one has not been provided
241
+ if ( ! this . s . explicitlyIgnoreSession && ! this . s . session && this . s . topology . hasSessionSupport ( ) ) {
242
+ this . s . session = this . s . topology . startSession ( { owner : this } ) ;
243
+ this . cursorState . session = this . s . session ;
244
+
245
+ if ( this . operation ) {
246
+ this . operation . session = this . s . session ;
247
+ }
248
+ }
231
249
}
232
250
233
251
CoreCursor . prototype . _initializeCursor . apply ( this , [ callback ] ) ;
@@ -1000,6 +1018,12 @@ Cursor.prototype.transformStream = function(options) {
1000
1018
* @return {Promise } returns Promise if no callback passed
1001
1019
*/
1002
1020
Cursor . prototype . explain = function ( callback ) {
1021
+ if ( this . operation ) {
1022
+ this . operation . explain = true ;
1023
+ executeOperation ( this . s . topology , this . operation , callback ) ;
1024
+ return ;
1025
+ }
1026
+
1003
1027
this . s . cmd . explain = true ;
1004
1028
1005
1029
// Do we have a readConcern
0 commit comments