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

Function constructor

src/operations/command.ts:86–111  ·  view source on GitHub ↗
(parent?: OperationParent, options?: CommandOperationOptions)

Source from the content-addressed store, hash-verified

84 explain?: Explain;
85
86 constructor(parent?: OperationParent, options?: CommandOperationOptions) {
87 super(options);
88 this.options = options ?? {};
89
90 // NOTE: this was explicitly added for the add/remove user operations, it's likely
91 // something we'd want to reconsider. Perhaps those commands can use `Admin`
92 // as a parent?
93 const dbNameOverride = options?.dbName || options?.authdb;
94 if (dbNameOverride) {
95 this.ns = new MongoDBNamespace(dbNameOverride, '$cmd');
96 } else {
97 this.ns = parent
98 ? parent.s.namespace.withCollection('$cmd')
99 : new MongoDBNamespace('admin', '$cmd');
100 }
101
102 this.readConcern = ReadConcern.fromOptions(options);
103 this.writeConcern = WriteConcern.fromOptions(options);
104
105 if (this.hasAspect(Aspect.EXPLAINABLE)) {
106 this.explain = Explain.fromOptions(options);
107 if (this.explain) validateExplainTimeoutOptions(this.options, this.explain);
108 } else if (options?.explain != null) {
109 throw new MongoInvalidArgumentError(`Option "explain" is not supported on this command`);
110 }
111 }
112
113 override get canRetryWrite(): boolean {
114 if (this.hasAspect(Aspect.EXPLAINABLE)) {

Callers

nothing calls this directly

Calls 3

withCollectionMethod · 0.80
fromOptionsMethod · 0.45

Tested by

no test coverage detected