@@ -4,19 +4,19 @@ cursor.forEach()
4
4
5
5
.. default-domain:: mongodb
6
6
7
- .. method:: cursor.forEach(function)
7
+ .. method:: cursor.forEach(< function> )
8
8
9
- The :method:`~cursor.forEach()` method iterates the cursor
10
- to apply function to each document from the cursor.
9
+ The :method:`~cursor.forEach()` method iterates the cursor to apply
10
+ a JavaScript ``< function>`` to each document from the cursor.
11
11
12
12
The :method:`~cursor.forEach()` method accepts the following
13
13
argument:
14
14
15
- :param function:
15
+ :param < function> :
16
16
17
17
JavaScript function to apply to each document from the
18
- cursor. The function signature includes a single argument
19
- which is passed the current document to process, as in the
18
+ cursor. The ``< function>`` signature includes a single argument
19
+ that is passed the current document to process, as in the
20
20
following prototype:
21
21
22
22
.. code-block:: javascript
@@ -41,18 +41,12 @@ cursor.forEach()
41
41
and thus, you can access ``arguments.length`` attribute to
42
42
determine the number of arguments.
43
43
44
- Consider the following example which appends the
45
- :method:`~cursor.forEach()` method to a
46
- :method:`~db.collection.find()` query to iterate through the cursor
47
- returned from the :method:`~db.collection.find()` and apply the
48
- function to each document:
44
+ The following example invokes the :method:`~cursor.forEach()` method
45
+ on the cursor returned by :method:`~db.collection.find()` to print
46
+ the name of each user in the collection:
49
47
50
48
.. code-block:: javascript
51
49
52
50
db.users.find().forEach( function(myDoc) { print( "user: " + myDoc.name ); } );
53
51
54
- The example finds all documents in the ``users`` collection and
55
- applies function to each document in order to print the name from each
56
- document.
57
-
58
52
.. seealso:: :method:`cursor.map()` for similar functionality.
0 commit comments