Skip to content

Commit

Permalink
fix(aggregate-operation): move type assertions to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst authored and daprahamian committed Aug 13, 2019
1 parent 8c2ed05 commit 25b27ff
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions lib/operations/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ class AggregateOperation extends CommandOperationV2 {
if (this.hasWriteStage) {
this.readPreference = ReadPreference.primary;
}

if (options.explain && (this.readConcern || this.writeConcern)) {
throw new MongoError(
'"explain" cannot be used on an aggregate call with readConcern/writeConcern'
);
}

if (options.cursor != null && typeof options.cursor !== 'object') {
throw new MongoError('cursor options must be an object');
}
}

get canRetryRead() {
Expand All @@ -52,6 +62,7 @@ class AggregateOperation extends CommandOperationV2 {
const command = { aggregate: this.target, pipeline: this.pipeline };

if (
this.readConcern &&
(!this.hasWriteStage || serverWireVersion >= MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT) &&
!inTransaction
) {
Expand Down Expand Up @@ -85,29 +96,13 @@ class AggregateOperation extends CommandOperationV2 {
}

if (options.explain) {
if (command.readConcern || command.writeConcern) {
callback(
new MongoError(
'"explain" cannot be used on an aggregate call with readConcern/writeConcern'
)
);

return;
}

command.explain = options.explain;
}

if (typeof options.comment === 'string') {
command.comment = options.comment;
}

// Validate that cursor options is valid
if (options.cursor != null && typeof options.cursor !== 'object') {
callback(new MongoError('cursor options must be an object'));
return;
}

command.cursor = options.cursor || {};
if (options.batchSize && !this.hasWriteStage) {
command.cursor.batchSize = options.batchSize;
Expand Down

0 comments on commit 25b27ff

Please sign in to comment.