@@ -170,23 +170,13 @@ export class MongoDBResponse extends OnDemandDocument {
170
170
/** @internal */
171
171
export class CursorResponse extends MongoDBResponse {
172
172
/**
173
- * This is a BSON document containing the following:
174
- * ```
175
- * { ok: 1, cursor: { id: 0n, nextBatch: new Array(0) } }
176
- * ```
177
- * This is used when the client side findCursor is closed by tracking the number returned and limit
178
- * to avoid an extra round trip. It provides a cursor response that the server _would_ return _if_
179
- * that round trip were to be made.
173
+ * This supports a feature of the FindCursor.
174
+ * It is an optimization to avoid an extra getMore when the limit has been reached
180
175
*/
181
- static emptyGetMore = new CursorResponse (
182
- Buffer . from (
183
- 'NgAAABBvawABAAAAA2N1cnNvcgAhAAAAEmlkAAAAAAAAAAAABG5leHRCYXRjaAAFAAAAAAAA' ,
184
- 'base64'
185
- )
186
- ) ;
176
+ static emptyGetMore = { id : new Long ( 0 ) , length : 0 , shift : ( ) => null } ;
187
177
188
178
static override is ( value : unknown ) : value is CursorResponse {
189
- return value instanceof CursorResponse ;
179
+ return value instanceof CursorResponse || value === CursorResponse . emptyGetMore ;
190
180
}
191
181
192
182
public id : Long ;
@@ -223,13 +213,9 @@ export class CursorResponse extends MongoDBResponse {
223
213
return null ;
224
214
}
225
215
226
- const result = this . batch ? .get ( this . iterated , BSONType . object , true ) ?? null ;
216
+ const result = this . batch . get ( this . iterated , BSONType . object , true ) ?? null ;
227
217
this . iterated += 1 ;
228
218
229
- if ( result == null ) {
230
- throw new MongoUnexpectedServerResponseError ( 'Cursor batch contains null values' ) ;
231
- }
232
-
233
219
if ( options ?. raw ) {
234
220
return result . toBytes ( ) ;
235
221
} else {
0 commit comments