- Reference >
- JavaScript Methods >
- cursor.forEach()
cursor.forEach()¶
-
cursor.forEach(<function>)¶ 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: - <function> – JavaScript function to apply to each document from the
cursor. The
<function>signature includes a single argument that is passed the current document to process.
The following example invokes the
forEach()method on the cursor returned byfind()to print the name of each user in the collection:See also
cursor.map()for similar functionality.- <function> – JavaScript function to apply to each document from the
cursor. The