Skip to content

Document db.collection.mapReduce return values #1895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 105 additions & 7 deletions source/reference/command/mapReduce.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ mapReduce
:start-after: start-finalize
:end-before: end-finalize

Examples
--------
Map-Reduce Examples
-------------------

In the :program:`mongo` shell, the :method:`db.collection.mapReduce()`
method is a wrapper around the :dbcommand:`mapReduce` command. The
Expand All @@ -101,14 +101,112 @@ For more information and examples, see the
:doc:`Map-Reduce </core/map-reduce>` page and
:doc:`/tutorial/perform-incremental-map-reduce`.

.. seealso::
.. _mapreduce-output:

- :doc:`/tutorial/troubleshoot-map-function`
Output
------

- :doc:`/tutorial/troubleshoot-reduce-function`
If you set the :ref:`out <mapReduce-out-cmd>` parameter to write the
output of the operation to a collection, the :dbcommand:`mapReduce`
command returns a document in the following form:

- :method:`db.collection.mapReduce()`
.. code-block:: javascript

- :doc:`/core/aggregation`
{
"result" : "map_reduce_example",
"timeMillis" : <milliseconds>,
"counts" : {
"input" : <int>,
"emit" : <int>,
"reduce" : <int>,
"output" : <int>
},
"ok" : 1,
}

If you set the :ref:`out <mapReduce-out-cmd>` parameter to output results
inline, the :dbcommand:`mapReduce` command returns a document in the
following form:

.. code-block:: javascript

{
"results" : [
{
"_id" : "abc123",
"value" : 0
},
{
"_id" : "ijk021",
"value" : 0
},
{
"_id" : "stu523",
"value" : null
},
{
"_id" : "xyz321",
"value" : 0
}
],
"timeMillis" : <milliseconds>,
"counts" : {
"input" : <int>,
"emit" : <int>,
"reduce" : <int>,
"output" : <int>
},
"ok" : 1
}

.. data:: mapReduce.result

For output sent to a collection, this value includes the collection
name where the :dbcommand:`mapReduce` command wrote the results. If the
:ref:`out <mapReduce-out-cmd>` parameter specified a database and
collection name, the value includes both names.

For output written inline, the result includes an array with the
``_id`` and ``value`` fields for each result.

.. data:: mapReduce.timeMillis

The command execution time in milliseconds.

.. data:: mapReduce.counts

Counts of function calls generated by the :dbcommand:`mapReduce` command.

.. data:: mapReduce.counts.input

The number of times the :dbcommand:`mapReduce` command called the ``input`` function.

.. data:: mapReduce.counts.emit

The number of times the :dbcommand:`mapReduce` command called the ``emit`` function.

.. data:: mapReduce.counts.reduce

The number of times the :dbcommand:`mapReduce` command called the ``reduce`` function.

.. data:: mapReduce.counts.output

The number of output values produced.

.. data:: mapReduce.ok

A value of ``1`` indicates the :dbcommand:`mapReduce` command ran
successfully. A value of ``0`` indicates an error.

Additional Information
----------------------

- :doc:`/tutorial/troubleshoot-map-function`

- :doc:`/tutorial/troubleshoot-reduce-function`

- :method:`db.collection.mapReduce()`

- :doc:`/core/aggregation`

.. slave-ok
26 changes: 18 additions & 8 deletions source/reference/method/db.collection.mapReduce.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,26 @@ db.collection.mapReduce()

.. include:: /includes/examples-map-reduce.rst

For more information and examples, see the
:doc:`Map-Reduce </core/map-reduce>` page and
:doc:`/tutorial/perform-incremental-map-reduce`.
Output
------

.. seealso::
For more information about the output the :dbcommand:`mapReduce` command
generates if you set the :ref:`out <mapReduce-out-cmd>` parameter to send
results to a collection, see the :ref:`Output <mapReduce-output>` section
of the :dbcommand:`mapReduce` page.

- :doc:`/tutorial/troubleshoot-map-function`
Additional Information
----------------------

- :doc:`/tutorial/troubleshoot-reduce-function`
- :doc:`/tutorial/troubleshoot-map-function`

- :dbcommand:`mapReduce` command
- :doc:`/tutorial/troubleshoot-reduce-function`

- :dbcommand:`mapReduce` command

- :doc:`/core/aggregation`

- :doc:`Map-Reduce </core/map-reduce>`

- :doc:`/tutorial/perform-incremental-map-reduce`

- :doc:`/core/aggregation`