Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/operations/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ export class AggregateOperation extends CommandOperation<CursorResponse> {
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');
}
Expand Down
6 changes: 3 additions & 3 deletions test/integration/crud/aggregation.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';

import { MongoInvalidArgumentError } from '../../../src/error';
import { MongoInvalidArgumentError, MongoServerError } from '../../../src/error';
import { type MongoClient } from '../../../src/mongo_client';
import { filterForCommands } from '../shared';

Expand Down Expand Up @@ -601,7 +601,7 @@ describe('Aggregation', function () {
.toArray()
.catch(error => error);

expect(error).to.be.instanceOf(MongoInvalidArgumentError);
expect(error).to.be.instanceOf(MongoServerError);
});

it('should fail if you try to use explain flag with { writeConcern: { j: true } }', async function () {
Expand All @@ -615,7 +615,7 @@ describe('Aggregation', function () {
.toArray()
.catch(error => error);

expect(error).to.be.instanceOf(MongoInvalidArgumentError);
expect(error).to.be.instanceOf(MongoServerError);
});

it('should ensure MaxTimeMS is correctly passed down into command execution when using a cursor', async function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
'use strict';
import { expect } from 'chai';

const { expect } = require('chai');
const { AggregateOperation } = require('../../../src/operations/aggregate');
import { AggregateOperation } from '../../../src/operations/aggregate';
import { MongoDBNamespace, WriteConcern } from '../../mongodb';

describe('AggregateOperation', function () {
const db = 'test';
const ns = new MongoDBNamespace('test', 'coll');

describe('#constructor', function () {
context('when out is in the options', function () {
const operation = new AggregateOperation(db, [], { out: 'test', dbName: db });
const operation = new AggregateOperation(ns, [], { out: 'test', dbName: ns.db });

it('sets hasWriteStage to true', function () {
expect(operation.hasWriteStage).to.be.true;
});
});

context('when $out is the last stage', function () {
const operation = new AggregateOperation(db, [{ $out: 'test' }], { dbName: db });
const operation = new AggregateOperation(ns, [{ $out: 'test' }], { dbName: ns.db });

it('sets hasWriteStage to true', function () {
expect(operation.hasWriteStage).to.be.true;
});
});

context('when $out is not the last stage', function () {
const operation = new AggregateOperation(db, [{ $out: 'test' }, { $project: { name: 1 } }], {
dbName: db
const operation = new AggregateOperation(ns, [{ $out: 'test' }, { $project: { name: 1 } }], {
dbName: ns.db
});

it('sets hasWriteStage to false', function () {
Expand All @@ -34,7 +34,9 @@ describe('AggregateOperation', function () {
});

context('when $merge is the last stage', function () {
const operation = new AggregateOperation(db, [{ $merge: { into: 'test' } }], { dbName: db });
const operation = new AggregateOperation(ns, [{ $merge: { into: 'test' } }], {
dbName: ns.db
});

it('sets hasWriteStage to true', function () {
expect(operation.hasWriteStage).to.be.true;
Expand All @@ -43,9 +45,9 @@ describe('AggregateOperation', function () {

context('when $merge is not the last stage', function () {
const operation = new AggregateOperation(
db,
ns,
[{ $merge: { into: 'test' } }, { $project: { name: 1 } }],
{ dbName: db }
{ dbName: ns.db }
);

it('sets hasWriteStage to false', function () {
Expand All @@ -54,19 +56,33 @@ describe('AggregateOperation', function () {
});

context('when no writable stages in empty pipeline', function () {
const operation = new AggregateOperation(db, [], { dbName: db });
const operation = new AggregateOperation(ns, [], { dbName: ns.db });

it('sets hasWriteStage to false', function () {
expect(operation.hasWriteStage).to.be.false;
});
});

context('when no writable stages', function () {
const operation = new AggregateOperation(db, [{ $project: { name: 1 } }], { dbName: db });
const operation = new AggregateOperation(ns, [{ $project: { name: 1 } }], { dbName: ns });

it('sets hasWriteStage to false', function () {
expect(operation.hasWriteStage).to.be.false;
});
});

context('when explain is set', function () {
context('when writeConcern is set', function () {
const operation = new AggregateOperation(ns, [], {
dbName: ns.db,
explain: true,
writeConcern: WriteConcern.fromOptions({ wtimeoutMS: 1000 })
});

it('does not raise an error', function () {
expect(operation.explain).to.exist;
});
});
});
});
});