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

@@ -5,6 +5,8 @@ const defineAspects = require('./operation').defineAspects;
const CommandOperationV2 = require('./command_v2');
const decorateWithCollation = require('../utils').decorateWithCollation;
const decorateWithReadConcern = require('../utils').decorateWithReadConcern;
const maxWireVersion = require('../core/utils').maxWireVersion;
const MongoError = require('../error').MongoError;
/**
* Return a list of distinct values for the given key across a collection.
@@ -65,13 +67,18 @@ class DistinctOperation extends CommandOperationV2 {
return callback(err, null);
}
if (this.explain && maxWireVersion(server) < 4) {
callback(new MongoError(`server does not support explain on distinct`));
return;
}
super.executeCommand(server, cmd, (err, result) => {
if (err) {
callback(err);
return;
}
callback(null, this.options.full ? result : result.values);
callback(null, this.options.full || this.explain ? result : result.values);
});
}
}
@@ -79,7 +86,8 @@ class DistinctOperation extends CommandOperationV2 {
defineAspects(DistinctOperation, [
Aspect.READ_OPERATION,
Aspect.RETRYABLE,
Aspect.EXECUTE_WITH_SELECTION
Aspect.EXECUTE_WITH_SELECTION,
Aspect.EXPLAINABLE
]);
module.exports = DistinctOperation;