diff --git a/src/operations/aggregate.ts b/src/operations/aggregate.ts index a11365a9e89..66d322f300c 100644 --- a/src/operations/aggregate.ts +++ b/src/operations/aggregate.ts @@ -85,12 +85,6 @@ export class AggregateOperation extends CommandOperation { delete this.options.writeConcern; } - if (this.explain && this.writeConcern) { - throw new MongoInvalidArgumentError( - 'Option "explain" cannot be used on an aggregate call with writeConcern' - ); - } - if (options?.cursor != null && typeof options.cursor !== 'object') { throw new MongoInvalidArgumentError('Cursor options must be an object'); } diff --git a/test/unit/operations/aggregate.test.js b/test/unit/operations/aggregate.test.js index 118140d95f9..1b179771ddf 100644 --- a/test/unit/operations/aggregate.test.js +++ b/test/unit/operations/aggregate.test.js @@ -7,6 +7,23 @@ describe('AggregateOperation', function () { const db = 'test'; describe('#constructor', function () { + context('when explain is in the options', function () { + context('when writeConcern is set', function () { + const operation = new AggregateOperation(db, [], { + explain: 'verbose', + writeConcern: { w: 1 } + }); + + it('sets explain on the operation', function () { + expect(operation.explain.verbosity).to.equal('verbose'); + }); + + it('sets the write concern on the operation', function () { + expect(operation.writeConcern.w).to.equal(1); + }); + }); + }); + context('when out is in the options', function () { const operation = new AggregateOperation(db, [], { out: 'test', dbName: db });