lib/operations/cursor_ops.js
function each(cursor, callback) {
  let Cursor = loadCursor();

  if (!callback) throw MongoError.create({ message: 'callback is mandatory', driver: true });
  if (cursor.isNotified()) return;
  if (cursor.s.state === Cursor.CLOSED || cursor.isDead()) {
    return handleCallback(
      callback,
      MongoError.create({ message: 'Cursor is closed', driver: true })
    );
  }

  if (cursor.s.state === Cursor.INIT) cursor.s.state = Cursor.OPEN;

  // Define function to avoid global scope escape
  let fn = null;
  // Trampoline all the entries
  if (cursor.bufferedCount() > 0) {
    while ((fn = loop(cursor, callback))) fn(cursor, callback);
    each(cursor, callback);
  } else {
    cursor.next((err, item) => {
      if (err) return handleCallback(callback, err);
      if (item == null) {
        return cursor.close({ skipKillCursors: true }, () => handleCallback(callback, null, null));
      }

      if (handleCallback(callback, null, item) === false) return;
      each(cursor, callback);
    });
  }
}
function each(cursor, callback) {
  let Cursor = loadCursor();

  if (!callback) throw MongoError.create({ message: 'callback is mandatory', driver: true });
  if (cursor.isNotified()) return;
  if (cursor.s.state === Cursor.CLOSED || cursor.isDead()) {
    return handleCallback(
      callback,
      MongoError.create({ message: 'Cursor is closed', driver: true })
    );
  }

  if (cursor.s.state === Cursor.INIT) cursor.s.state = Cursor.OPEN;

  // Define function to avoid global scope escape
  let fn = null;
  // Trampoline all the entries
  if (cursor.bufferedCount() > 0) {
    while ((fn = loop(cursor, callback))) fn(cursor, callback);
    each(cursor, callback);
  } else {
    cursor.next((err, item) => {
      if (err) return handleCallback(callback, err);
      if (item == null) {
        return cursor.close({ skipKillCursors: true }, () => handleCallback(callback, null, null));
      }

      if (handleCallback(callback, null, item) === false) return;
      each(cursor, callback);
    });
  }
}
function each ( cursor , callback ) { let Cursor = loadCursor ( ) ; if ( ! callback ) throw MongoError . create ( { message : 'callback is mandatory' , driver : true } ) ; if ( cursor . isNotified ( ) ) return ; if ( cursor . s . state === Cursor . CLOSED || cursor . isDead ( ) ) { return handleCallback ( callback , MongoError . create ( { message : 'Cursor is closed' , driver : true } ) ) ; } if ( cursor . s . state === Cursor . INIT ) cursor . s . state = Cursor . OPEN ; // Define function to avoid global scope escape let fn = null ; // Trampoline all the entries if ( cursor . bufferedCount ( ) > 0 ) { while ( ( fn = loop ( cursor , callback ) ) ) fn ( cursor , callback ) ; each ( cursor , callback ) ; } else { cursor . next ( ( err , item ) => { if ( err ) return handleCallback ( callback , err ) ; if ( item == null ) { return cursor . close ( { skipKillCursors : true } , ( ) => handleCallback ( callback , null , null ) ) ; } if ( handleCallback ( callback , null , item ) === false ) return ; each ( cursor , callback ) ; } ) ; } }
Iterates over all the documents for this cursor. See Cursor.prototype.each for more information.

@method
@deprecated
@param {Cursor} cursor The Cursor instance on which to run.
@param {Cursor~resultCallback} callback The result callback.
Iterates over all the documents for this cursor . See Cursor . prototype . each for more information .