Skip to content

Commit

Permalink
fix(cursor): throw error when using aggregation cursor as async iterator
Browse files Browse the repository at this point in the history
Fix #8280
  • Loading branch information
vkarpov15 committed Nov 3, 2019
1 parent 69bf575 commit 4c090c5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/cursor/AggregationCursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

'use strict';

const MongooseError = require('../error/mongooseError');
const Readable = require('stream').Readable;
const eachAsync = require('../helpers/cursor/eachAsync');
const util = require('util');
Expand Down Expand Up @@ -94,6 +95,15 @@ AggregationCursor.prototype._read = function() {
});
};

if (Symbol.asyncIterator != null) {
const msg = 'Mongoose does not support using async iterators with an ' +
'existing aggregation cursor. See http://bit.ly/mongoose-async-iterate-aggregation';

AggregationCursor.prototype[Symbol.asyncIterator] = function() {
throw new MongooseError(msg);
};
}

/**
* Registers a transform function which subsequently maps documents retrieved
* via the streams interface or `.next()`
Expand Down

0 comments on commit 4c090c5

Please sign in to comment.