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
3 changes: 3 additions & 0 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2426,6 +2426,7 @@ function decorateWithCollation(command, self, options) {
* @param {boolean} [options.promoteValues=true] Promotes BSON values to native types where possible, set to false to only receive wrapper types.
* @param {boolean} [options.promoteBuffers=false] Promotes Binary BSON values to native Node Buffers.
* @param {object} [options.collation=null] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
* @param {string} [options.comment] Add a comment to an aggregation command
* @param {ClientSession} [options.session] optional session to use for this operation
* @param {Collection~resultCallback} callback The command result callback
* @return {(null|AggregationCursor)}
Expand Down Expand Up @@ -2515,6 +2516,8 @@ Collection.prototype.aggregate = function(pipeline, options, callback) {
// If explain has been specified add it
if (options.explain) 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') {
throw toError('cursor options must be an object');
Expand Down
39 changes: 39 additions & 0 deletions test/functional/aggregation_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,45 @@ describe('Aggregation', function() {
}
);

it('should pass a comment down via the aggregation command', {
metadata: {
requires: {
mongodb: '>=3.5.0',
topology: 'single',
node: '>=4.8.5'
}
},
test: function(done) {
const client = this.configuration.newClient({ w: 1 }, { poolSize: 1 });
const databaseName = this.configuration.db;

const comment = 'Darmok and Jalad at Tanagra';

client.connect(function(err, client) {
expect(err).to.be.null;

const db = client.db(databaseName);
const collection = db.collection('testingPassingDownTheAggregationCommand');

const command = db.command;

db.command = function(c) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice!

expect(c).to.be.an('object');
expect(c.comment)
.to.be.a('string')
.and.to.equal('comment');
command.apply(db, Array.prototype.slice.call(arguments, 0));
};

collection.aggregate([{ $project: { _id: 1 } }], { comment }, function(err, r) {
expect(err).to.be.null;
expect(r).to.not.be.null;
done();
});
});
}
});

/**
* Correctly call the aggregation framework to return a cursor with batchSize 1 and get the first result using next
*
Expand Down