Skip to content

Commit

Permalink
feat(aggregation): adds support for comment in aggregation command (#…
Browse files Browse the repository at this point in the history
…1571)

Adds a "comment" field to the aggregation command

Fixes NODE-1149
  • Loading branch information
daprahamian authored Nov 17, 2017
1 parent 21d7e70 commit 4ac475c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
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) {
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

0 comments on commit 4ac475c

Please sign in to comment.