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

Function resolveOptions

src/utils.ts:513–559  ·  src/utils.ts::resolveOptions
(
  parent: OperationParent | undefined,
  options?: T
)

Source from the content-addressed store, hash-verified

511 * @internal
512 */
513export function resolveOptions<T extends CommandOperationOptions>(
514 parent: OperationParent | undefined,
515 options?: T
516): T {
517 const result: T = Object.assign({}, options, resolveBSONOptions(options, parent));
518
519 const timeoutMS = options?.timeoutMS ?? parent?.timeoutMS;
520 class="cm">// Users cannot pass a readConcern/writeConcern to operations in a transaction
521 const session = options?.session;
522
523 if (!session?.inTransaction()) {
524 const readConcern = ReadConcern.fromOptions(options) ?? parent?.readConcern;
525 if (readConcern) {
526 result.readConcern = readConcern;
527 }
528
529 let writeConcern = WriteConcern.fromOptions(options) ?? parent?.writeConcern;
530 if (writeConcern) {
531 if (timeoutMS != null) {
532 writeConcern = WriteConcern.fromOptions({
533 writeConcern: {
534 ...writeConcern,
535 wtimeout: undefined,
536 wtimeoutMS: undefined
537 }
538 });
539 }
540 result.writeConcern = writeConcern;
541 }
542 }
543
544 result.timeoutMS = timeoutMS;
545
546 const readPreference = ReadPreference.fromOptions(options) ?? parent?.readPreference;
547 if (readPreference) {
548 result.readPreference = readPreference;
549 }
550
551 const isConvenientTransaction = session?.explicit && session?.timeoutContext != null;
552 if (isConvenientTransaction && options?.timeoutMS != null) {
553 throw new MongoInvalidArgumentError(
554 class="st">'An operation cannot be given a timeoutMS setting when inside a withTransaction call that has a timeoutMS setting'
555 );
556 }
557
558 return result;
559}
560
561export function isSuperset(set: Set<any> | any[], subset: Set<any> | any[]): boolean {
562 set = Array.isArray(set) ? new Set(set) : set;

Callers 15

insertOneMethod · 0.90
insertManyMethod · 0.90
bulkWriteMethod · 0.90
updateOneMethod · 0.90
replaceOneMethod · 0.90
updateManyMethod · 0.90
deleteOneMethod · 0.90
deleteManyMethod · 0.90
renameMethod · 0.90
findMethod · 0.90
optionsMethod · 0.90
createIndexMethod · 0.90

Calls 3

resolveBSONOptionsFunction · 0.90
inTransactionMethod · 0.80
fromOptionsMethod · 0.45

Tested by

no test coverage detected