diff --git a/lib/cursor.js b/lib/cursor.js index d7cd06493fe..69293213ec0 100644 --- a/lib/cursor.js +++ b/lib/cursor.js @@ -729,8 +729,14 @@ Cursor.prototype.each = deprecate(function(callback) { * @return {Promise} if no callback supplied */ Cursor.prototype.forEach = function(iterator, callback) { + // Rewind cursor state + this.rewind(); + + // Set current cursor to INIT + this.s.state = Cursor.INIT; + if (typeof callback === 'function') { - this.each((err, doc) => { + each(this, (err, doc) => { if (err) { callback(err); return false; @@ -748,7 +754,7 @@ Cursor.prototype.forEach = function(iterator, callback) { }); } else { return new this.s.promiseLibrary((fulfill, reject) => { - this.each((err, doc) => { + each(this, (err, doc) => { if (err) { reject(err); return false;