Skip to content

Commit

Permalink
fix(aggregate): add .pipeline() helper to get the current pipeline
Browse files Browse the repository at this point in the history
Fix #5825
  • Loading branch information
vkarpov15 committed Nov 17, 2017
1 parent 001f98b commit 22d4657
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,22 @@ Aggregate.prototype.facet = function(options) {
return this.append({$facet: options});
};

/**
* Returns the current pipeline
*
* ####Example:
*
* MyModel.aggregate().match({ test: 1 }).pipeline(); // [{ $match: { test: 1 } }]
*
* @return {Array}
* @api public
*/


Aggregate.prototype.pipeline = function() {
return this._pipeline;
};

/**
* Executes the aggregate pipeline on the currently bound Model.
*
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions test/aggregate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,18 @@ describe('aggregate: ', function() {
});
});

it('pipeline() (gh-5825)', function(done) {
var aggregate = new Aggregate();

var pipeline = aggregate.
model(db.model('Employee')).
match({ sal: { $lt: 16000 } }).
pipeline();

assert.deepEqual(pipeline, [{ $match: { sal: { $lt: 16000 } } }]);
done();
});

it('explain()', function(done) {
var aggregate = new Aggregate();
start.mongodVersion(function(err, version) {
Expand Down

0 comments on commit 22d4657

Please sign in to comment.