集計コマンドの比較
注意
map-reduce の代替としての集計パイプライン
MongoDB 5.0 以降、map-reduce は非推奨になっています。
map-reduceの代わりに、集計パイプラインを使用する必要があります。 集計パイプラインは、map-reduce よりもパフォーマンスとユーザビリティが優れています。
map-reduce 操作は、
$group
、$merge
などの集計パイプライン ステージを使用して書き換えることができます。
カスタム機能を必要とする map-reduce 操作には、
$accumulator
と$function
の集計演算子を使用できます。 これらの演算子を使用して、JavaScript でカスタム集計式を定義できます。
map-reduce を集計パイプラインに置き換える例については、以下を参照してください。
Aggregation Commands Comparison Table
The following table provides a brief overview of the features of the MongoDB aggregation commands.
説明 | Implements the Map-Reduce aggregation for processing large data sets. | |
主な特徴 | Pipeline operators can be repeated as needed. Pipeline operators need not produce one output document for every input document. Can also generate new documents or filter out documents. Using the | In addition to grouping operations, can perform complex aggregation tasks as well as perform incremental aggregation on continuously growing datasets. |
Flexibility | You can define custom aggregation expressions with You can also add computed fields, create new virtual sub-objects, and
extract sub-fields into the top-level of results by using the
See | Custom See |
Output Results | Returns results as a cursor. If the pipeline includes the
With With | Returns results in various options (inline, new collection, merge,
replace, reduce). See |
シャーディング | Supports non-sharded and sharded input collections.
| Supports non-sharded and sharded input collections. |
More Information |
以下も参照してください。