Skip to content

Commit a9d4de5

Browse files
committed
handle NO_INHERIT_OPTIONS
1 parent 373fa7c commit a9d4de5

File tree

7 files changed

+14
-16
lines changed

7 files changed

+14
-16
lines changed

src/collection.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,9 @@ export class Collection implements OperationParent {
565565
callback?: Callback<Collection>
566566
): Promise<Collection> | void {
567567
if (typeof options === 'function') (callback = options), (options = {});
568-
options = resolveInheritedOptions(this, options);
568+
569+
// Intentionally, we do not inherit options from parent for this operation.
570+
options = options || {};
569571
options.readPreference = ReadPreference.PRIMARY;
570572
return executeOperation(
571573
getTopology(this),

src/db.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ export class Db implements OperationParent {
281281
callback?: Callback<Document>
282282
): Promise<Document> | void {
283283
if (typeof options === 'function') (callback = options), (options = {});
284-
options = resolveInheritedOptions(this, options);
284+
285+
// Intentionally, we do not inherit options from parent for this operation.
286+
options = options || {};
285287

286288
return executeOperation(
287289
getTopology(this),
@@ -455,7 +457,9 @@ export class Db implements OperationParent {
455457
callback?: Callback<Collection>
456458
): Promise<Collection> | void {
457459
if (typeof options === 'function') (callback = options), (options = {});
458-
options = resolveInheritedOptions(this, options);
460+
461+
// Intentionally, we do not inherit options from parent for this operation.
462+
options = options || {};
459463
options.readPreference = ReadPreference.PRIMARY;
460464

461465
// Add return new collection
@@ -555,7 +559,9 @@ export class Db implements OperationParent {
555559
callback?: Callback<void>
556560
): Promise<void> | void {
557561
if (typeof options === 'function') (callback = options), (options = {});
558-
options = resolveInheritedOptions(this, options);
562+
563+
// Intentionally, we do not inherit options from parent for this operation.
564+
options = options || {};
559565

560566
return executeOperation(
561567
getTopology(this),

src/operations/command.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ export abstract class CommandOperation<
7373
: new MongoDBNamespace('admin', '$cmd');
7474
}
7575

76-
// todo what about this.hasAspect(Aspect.NO_INHERIT_OPTIONS)
7776
const readPref = ReadPreference.fromOptions(options);
7877
this.readPreference =
7978
this.hasAspect(Aspect.WRITE_OPERATION) || readPref === undefined

src/operations/operation.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import type { Server } from '../sdam/server';
77
export const Aspect = {
88
READ_OPERATION: Symbol('READ_OPERATION'),
99
WRITE_OPERATION: Symbol('WRITE_OPERATION'),
10-
RETRYABLE: Symbol('RETRYABLE'),
11-
NO_INHERIT_OPTIONS: Symbol('NO_INHERIT_OPTIONS')
10+
RETRYABLE: Symbol('RETRYABLE')
1211
} as const;
1312

1413
/** @public */

src/operations/run_command.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { CommandOperation, CommandOperationOptions, OperationParent } from './command';
2-
import { defineAspects, Aspect } from './operation';
32
import { MongoDBNamespace, Callback } from '../utils';
43
import type { Server } from '../sdam/server';
54
import type { Document } from '../bson';
@@ -34,6 +33,3 @@ export class RunAdminCommandOperation<
3433
this.ns = new MongoDBNamespace('admin');
3534
}
3635
}
37-
38-
defineAspects(RunCommandOperation, [Aspect.NO_INHERIT_OPTIONS]);
39-
defineAspects(RunAdminCommandOperation, [Aspect.NO_INHERIT_OPTIONS]);

src/read_preference.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { TagSet } from './sdam/server_description';
2-
import type { OperationParent } from './operations/command';
32
import type { Document } from './bson';
43
import type { ClientSession } from './sessions';
54

src/utils.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,9 +1189,6 @@ export function resolveInheritedOptions<T extends CommandOperationOptions>(
11891189
}
11901190

11911191
const bsonOptions = resolveBSONOptions(result, parent);
1192-
Object.assign(result, bsonOptions);
11931192

1194-
// todo: are there others?
1195-
1196-
return result;
1193+
return { ...result, ...bsonOptions };
11971194
}

0 commit comments

Comments
 (0)