@@ -1656,6 +1656,72 @@ Valid options to ``#out`` are:
16561656- ``reduce: "name"``: Store in a collection with the
16571657 provided name, and reduce all existing results in that collection.
16581658
1659+ Raw Results
1660+ -----------
1661+
1662+ Results of Map/Reduce execution can be retrieved via the ``execute`` method
1663+ or its aliases ``raw`` and ``results``:
1664+
1665+ .. code-block:: ruby
1666+
1667+ mr = Band.where(:likes.gt => 100).map_reduce(map, reduce).out(inline: 1)
1668+
1669+ mr.execute
1670+ # => {"results"=>[{"_id"=>"Tool", "value"=>{"likes"=>200.0}}],
1671+ "timeMillis"=>14,
1672+ "counts"=>{"input"=>4, "emit"=>4, "reduce"=>1, "output"=>1},
1673+ "ok"=>1.0,
1674+ "$clusterTime"=>{"clusterTime"=>#<BSON::Timestamp:0x00005633c2c2ad20 @seconds=1590105400, @increment=1>, "signature"=>{"hash"=><BSON::Binary:0x12240 type=generic data=0x0000000000000000...>, "keyId"=>0}},
1675+ "operationTime"=>#<BSON::Timestamp:0x00005633c2c2aaf0 @seconds=1590105400, @increment=1>}
1676+
1677+
1678+ Statistics
1679+ ----------
1680+
1681+ MongoDB servers 4.2 and lower provide Map/Reduce execution statistics. As of
1682+ MongoDB 4.4, Map/Reduce is implemented via the aggregation pipeline and
1683+ statistics described in this section are not available.
1684+
1685+ The following methods are provided on the ``MapReduce`` object:
1686+
1687+ - ``counts``: Number of documents read, emitted, reduced and output through
1688+ the pipeline.
1689+ - ``input``, ``emitted``, ``reduced``, ``output``: individual count methods.
1690+ Note that ``emitted`` and ``reduced`` methods are named differently from
1691+ hash keys in ``counts``.
1692+ - ``time``: The time, in milliseconds, that Map/Reduce pipeline took to execute.
1693+
1694+ The following code illustrates retrieving the statistics:
1695+
1696+ .. code-block:: ruby
1697+
1698+ mr = Band.where(:likes.gt => 100).map_reduce(map, reduce).out(inline: 1)
1699+
1700+ mr.counts
1701+ # => {"input"=>4, "emit"=>4, "reduce"=>1, "output"=>1}
1702+
1703+ mr.input
1704+ # => 4
1705+
1706+ mr.emitted
1707+ # => 4
1708+
1709+ mr.reduced
1710+ # => 1
1711+
1712+ mr.output
1713+ # => 1
1714+
1715+ mr.time
1716+ # => 14
1717+
1718+ .. note::
1719+
1720+ Each statistics method invocation re-executes the Map/Reduce pipeline.
1721+ The results of execution are not stored by Mongoid. Consider using the
1722+ ``execute`` method to retrieve the raw results and obtaining the statistics
1723+ from the raw results if multiple statistics are desired.
1724+
16591725
16601726Full Text Search
16611727================
0 commit comments