This commit is contained in:
Jonasz Bigda
2023-03-25 21:51:42 +01:00
parent 0db1d5117e
commit b332e9ceb0
1044 changed files with 37502 additions and 63938 deletions

View File

@@ -2,12 +2,14 @@
const Aspect = require('./operation').Aspect;
const OperationBase = require('./operation').OperationBase;
const resolveReadPreference = require('../utils').resolveReadPreference;
const ReadPreference = require('../core').ReadPreference;
const ReadConcern = require('../read_concern');
const WriteConcern = require('../write_concern');
const maxWireVersion = require('../core/utils').maxWireVersion;
const decorateWithExplain = require('../utils').decorateWithExplain;
const commandSupportsReadConcern = require('../core/sessions').commandSupportsReadConcern;
const MongoError = require('../error').MongoError;
const MongoError = require('../core/error').MongoError;
const extractCommand = require('../command_utils').extractCommand;
const SUPPORTS_WRITE_CONCERN_AND_COLLATION = 5;
@@ -16,10 +18,12 @@ class CommandOperationV2 extends OperationBase {
super(options);
this.ns = parent.s.namespace.withCollection('$cmd');
this.readPreference = resolveReadPreference(parent, this.options);
this.readConcern = resolveReadConcern(parent, this.options);
this.writeConcern = resolveWriteConcern(parent, this.options);
this.explain = false;
const propertyProvider = this.hasAspect(Aspect.NO_INHERIT_OPTIONS) ? undefined : parent;
this.readPreference = this.hasAspect(Aspect.WRITE_OPERATION)
? ReadPreference.primary
: ReadPreference.resolve(propertyProvider, this.options);
this.readConcern = resolveReadConcern(propertyProvider, this.options);
this.writeConcern = resolveWriteConcern(propertyProvider, this.options);
if (operationOptions && typeof operationOptions.fullResponse === 'boolean') {
this.fullResponse = true;
@@ -76,8 +80,22 @@ class CommandOperationV2 extends OperationBase {
cmd.comment = options.comment;
}
if (this.hasAspect(Aspect.EXPLAINABLE) && this.explain) {
if (serverWireVersion < 6 && cmd.aggregate) {
// Prior to 3.6, with aggregate, verbosity is ignored, and we must pass in "explain: true"
cmd.explain = true;
} else {
cmd = decorateWithExplain(cmd, this.explain);
}
}
if (this.logger && this.logger.isDebug()) {
this.logger.debug(`executing command ${JSON.stringify(cmd)} against ${this.ns}`);
const extractedCommand = extractCommand(cmd);
this.logger.debug(
`executing command ${JSON.stringify(
extractedCommand.shouldRedact ? `${extractedCommand.name} details REDACTED` : cmd
)} against ${this.ns}`
);
}
server.command(this.ns.toString(), cmd, this.options, (err, result) => {
@@ -97,11 +115,11 @@ class CommandOperationV2 extends OperationBase {
}
function resolveWriteConcern(parent, options) {
return WriteConcern.fromOptions(options) || parent.writeConcern;
return WriteConcern.fromOptions(options) || (parent && parent.writeConcern);
}
function resolveReadConcern(parent, options) {
return ReadConcern.fromOptions(options) || parent.readConcern;
return ReadConcern.fromOptions(options) || (parent && parent.readConcern);
}
module.exports = CommandOperationV2;