Skip to content

Commit 25b27ff

Browse files
mbroadstdaprahamian
authored andcommitted
fix(aggregate-operation): move type assertions to constructor
1 parent 8c2ed05 commit 25b27ff

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

lib/operations/aggregate.js

+11-16
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ class AggregateOperation extends CommandOperationV2 {
3838
if (this.hasWriteStage) {
3939
this.readPreference = ReadPreference.primary;
4040
}
41+
42+
if (options.explain && (this.readConcern || this.writeConcern)) {
43+
throw new MongoError(
44+
'"explain" cannot be used on an aggregate call with readConcern/writeConcern'
45+
);
46+
}
47+
48+
if (options.cursor != null && typeof options.cursor !== 'object') {
49+
throw new MongoError('cursor options must be an object');
50+
}
4151
}
4252

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

5464
if (
65+
this.readConcern &&
5566
(!this.hasWriteStage || serverWireVersion >= MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT) &&
5667
!inTransaction
5768
) {
@@ -85,29 +96,13 @@ class AggregateOperation extends CommandOperationV2 {
8596
}
8697

8798
if (options.explain) {
88-
if (command.readConcern || command.writeConcern) {
89-
callback(
90-
new MongoError(
91-
'"explain" cannot be used on an aggregate call with readConcern/writeConcern'
92-
)
93-
);
94-
95-
return;
96-
}
97-
9899
command.explain = options.explain;
99100
}
100101

101102
if (typeof options.comment === 'string') {
102103
command.comment = options.comment;
103104
}
104105

105-
// Validate that cursor options is valid
106-
if (options.cursor != null && typeof options.cursor !== 'object') {
107-
callback(new MongoError('cursor options must be an object'));
108-
return;
109-
}
110-
111106
command.cursor = options.cursor || {};
112107
if (options.batchSize && !this.hasWriteStage) {
113108
command.cursor.batchSize = options.batchSize;

0 commit comments

Comments
 (0)