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

Method findOne

src/collection.ts:542–555  ·  view source on GitHub ↗
(
    filter: Filter<TSchema> = {},
    options: Omit<FindOneOptions, 'timeoutMode'> & Abortable = {}
  )

Source from the content-addressed store, hash-verified

540 ): Promise<T | null>;
541
542 async findOne(
543 filter: Filter<TSchema> = {},
544 options: Omit<FindOneOptions, 'timeoutMode'> & Abortable = {}
545 ): Promise<WithId<TSchema> | null> {
546 // Explicitly set the limit to 1 and singleBatch to true for all commands, per the spec.
547 // noCursorTimeout must be unset as well as batchSize.
548 // See: https://github.com/mongodb/specifications/blob/master/source/crud/crud.md#findone-api-details
549 const { ...opts } = options;
550 opts.singleBatch = true;
551 const cursor = this.find(filter, opts).limit(1);
552 const result = await cursor.next();
553 await cursor.close();
554 return result;
555 }
556
557 /**
558 * Creates a cursor for a filter that can be used to iterate over results from MongoDB

Callers 15

operations.tsFile · 0.80
ldap.test.tsFile · 0.80
makeConnectionTestFunction · 0.80
testConnectionFunction · 0.80
objectid.test.tsFile · 0.80
sessions.test.tsFile · 0.80
testFunction · 0.80
runTaskGroupFunction · 0.80

Calls 4

findMethod · 0.95
limitMethod · 0.45
nextMethod · 0.45
closeMethod · 0.45

Tested by 6

makeConnectionTestFunction · 0.64
testConnectionFunction · 0.64
testFunction · 0.64
runTaskGroupFunction · 0.64
deadlockTestFunction · 0.64
defineCorpusTestsFunction · 0.64