The forEach() method iterates the cursor to apply a JavaScript <function> to each document from the cursor.
The forEach() method accepts the following argument:
| Parameters: |
|
|---|
The following example invokes the forEach() method on the cursor returned by find() to print the name of each user in the collection:
db.users.find().forEach( function(myDoc) { print( "user: " + myDoc.name ); } );
See also
cursor.map() for similar functionality.