On this page本页内容
Map-reduce supports operations on sharded collections, both as an input and as an output. Map reduce支持分片集合上的操作,既可以作为输入,也可以作为输出。This section describes the behaviors of 本节描述特定于分片集合的mapReduce
specific to sharded collections.mapReduce
行为。
However, starting in version 4.2, MongoDB deprecates the map-reduce option to create a new sharded collection as well as the use of the 但是,从版本4.2开始,MongoDB不推荐使用map-reduce选项来创建新的分片集合,也不推荐使用分片选项来创建map-reduce。sharded
option for map-reduce. To output to a sharded collection, create the sharded collection first. 要输出到分片集合,请首先创建分片集合。MongoDB 4.2 also deprecates the replacement of an existing sharded collection.MongoDB 4.2还反对替换现有的分片集合。
When using sharded collection as the input for a map-reduce operation, 当使用分片集合作为map-reduce操作的输入时,mongos
will automatically dispatch the map-reduce job to each shard in parallel. mongos
将自动并行地将map-reduce作业分派给每个分片。There is no special option required. 不需要特殊选项。mongos
will wait for jobs on all shards to finish.mongos
将等待所有碎片上的作业完成。
If the 如果out
field for mapReduce
has the sharded
value, MongoDB shards the output collection using the _id
field as the shard key.mapReduce
的out
字段具有shared值,则MongoDB使用_id
字段作为shard键对输出集合进行切分。
Note
Starting in version 4.2, MongoDB deprecates the use of the 从版本4.2开始,MongoDB不赞成对sharded
option for mapReduce
/db.collection.mapReduce
.mapReduce
/db.collection.mapReduce
使用sharded
选项。
To output to a sharded collection:要输出到分片集合,请执行以下操作:
Starting in version 4.2, MongoDB deprecates the map-reduce option to create a new sharded collection and the use of the 从4.2版开始,MongoDB不推荐使用map-reduce选项来创建新的分片集合,也不推荐使用分片选项进行map-reduce。sharded
option for map-reduce. As such, to output to a sharded collection, create the sharded collection first.因此,要输出到分片集合,请首先创建分片集合。
If you did not create the sharded collection first, MongoDB creates and shards the collection on the 如果您没有首先创建切分集合,MongoDB将在_id
field. _id
字段中创建并切分集合。However, it is recommended that you create the sharded collection first.但是,建议您首先创建分片集合。
mongos
reduce
/finalize
,并在本地写入输出集合。Note