MCPcopy
hub / github.com/mongodb/node-mongodb-native / constructor

Function constructor

src/cursor/abstract_cursor.ts:258–364  ·  view source on GitHub ↗

@internal

(
    client: MongoClient,
    namespace: MongoDBNamespace,
    options: AbstractCursorOptions & Abortable = {}
  )

Source from the content-addressed store, hash-verified

256
257 /** @internal */
258 protected constructor(
259 client: MongoClient,
260 namespace: MongoDBNamespace,
261 options: AbstractCursorOptions & Abortable = {}
262 ) {
263 super();
264 this.on('error', noop);
265
266 if (!client.s.isMongoClient) {
267 throw new MongoRuntimeError('Cursor must be constructed with MongoClient');
268 }
269 this.cursorClient = client;
270 this.cursorNamespace = namespace;
271 this.cursorId = null;
272 this.initialized = false;
273 this.isClosed = false;
274 this.isKilled = false;
275 this.cursorOptions = {
276 readPreference:
277 options.readPreference && options.readPreference instanceof ReadPreference
278 ? options.readPreference
279 : ReadPreference.primary,
280 ...pluckBSONSerializeOptions(options),
281 timeoutMS: options?.timeoutContext?.csotEnabled()
282 ? options.timeoutContext.timeoutMS
283 : options.timeoutMS,
284 tailable: options.tailable,
285 awaitData: options.awaitData
286 };
287
288 if (this.cursorOptions.timeoutMS != null) {
289 if (options.timeoutMode == null) {
290 if (options.tailable) {
291 if (options.awaitData) {
292 if (
293 options.maxAwaitTimeMS != null &&
294 options.maxAwaitTimeMS >= this.cursorOptions.timeoutMS
295 )
296 throw new MongoInvalidArgumentError(
297 'Cannot specify maxAwaitTimeMS >= timeoutMS for a tailable awaitData cursor'
298 );
299 }
300
301 this.cursorOptions.timeoutMode = CursorTimeoutMode.ITERATION;
302 } else {
303 this.cursorOptions.timeoutMode = CursorTimeoutMode.LIFETIME;
304 }
305 } else {
306 if (options.tailable && options.timeoutMode === CursorTimeoutMode.LIFETIME) {
307 throw new MongoInvalidArgumentError(
308 "Cannot set tailable cursor's timeoutMode to LIFETIME"
309 );
310 }
311 this.cursorOptions.timeoutMode = options.timeoutMode;
312 }
313 } else {
314 if (options.timeoutMode != null)
315 throw new MongoInvalidArgumentError('Cannot set timeoutMode without setting timeoutMS');

Callers

nothing calls this directly

Calls 6

addAbortListenerFunction · 0.90
onMethod · 0.80
csotEnabledMethod · 0.45
fromOptionsMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected