Skip to content

Commit 4ac475c

Browse files
authored
feat(aggregation): adds support for comment in aggregation command (#1571)
Adds a "comment" field to the aggregation command Fixes NODE-1149
1 parent 21d7e70 commit 4ac475c

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

lib/collection.js

+3
Original file line numberDiff line numberDiff line change
@@ -2426,6 +2426,7 @@ function decorateWithCollation(command, self, options) {
24262426
* @param {boolean} [options.promoteValues=true] Promotes BSON values to native types where possible, set to false to only receive wrapper types.
24272427
* @param {boolean} [options.promoteBuffers=false] Promotes Binary BSON values to native Node Buffers.
24282428
* @param {object} [options.collation=null] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
2429+
* @param {string} [options.comment] Add a comment to an aggregation command
24292430
* @param {ClientSession} [options.session] optional session to use for this operation
24302431
* @param {Collection~resultCallback} callback The command result callback
24312432
* @return {(null|AggregationCursor)}
@@ -2515,6 +2516,8 @@ Collection.prototype.aggregate = function(pipeline, options, callback) {
25152516
// If explain has been specified add it
25162517
if (options.explain) command.explain = options.explain;
25172518

2519+
if (typeof options.comment === 'string') command.comment = options.comment;
2520+
25182521
// Validate that cursor options is valid
25192522
if (options.cursor != null && typeof options.cursor !== 'object') {
25202523
throw toError('cursor options must be an object');

test/functional/aggregation_tests.js

+39
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,45 @@ describe('Aggregation', function() {
10811081
}
10821082
);
10831083

1084+
it('should pass a comment down via the aggregation command', {
1085+
metadata: {
1086+
requires: {
1087+
mongodb: '>=3.5.0',
1088+
topology: 'single',
1089+
node: '>=4.8.5'
1090+
}
1091+
},
1092+
test: function(done) {
1093+
const client = this.configuration.newClient({ w: 1 }, { poolSize: 1 });
1094+
const databaseName = this.configuration.db;
1095+
1096+
const comment = 'Darmok and Jalad at Tanagra';
1097+
1098+
client.connect(function(err, client) {
1099+
expect(err).to.be.null;
1100+
1101+
const db = client.db(databaseName);
1102+
const collection = db.collection('testingPassingDownTheAggregationCommand');
1103+
1104+
const command = db.command;
1105+
1106+
db.command = function(c) {
1107+
expect(c).to.be.an('object');
1108+
expect(c.comment)
1109+
.to.be.a('string')
1110+
.and.to.equal('comment');
1111+
command.apply(db, Array.prototype.slice.call(arguments, 0));
1112+
};
1113+
1114+
collection.aggregate([{ $project: { _id: 1 } }], { comment }, function(err, r) {
1115+
expect(err).to.be.null;
1116+
expect(r).to.not.be.null;
1117+
done();
1118+
});
1119+
});
1120+
}
1121+
});
1122+
10841123
/**
10851124
* Correctly call the aggregation framework to return a cursor with batchSize 1 and get the first result using next
10861125
*

0 commit comments

Comments
 (0)