diff --git a/lib/cursor/AggregationCursor.js b/lib/cursor/AggregationCursor.js index 45acc94d4a8..03b6912464a 100644 --- a/lib/cursor/AggregationCursor.js +++ b/lib/cursor/AggregationCursor.js @@ -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'); @@ -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()`