// JavaScript source code db.runCommand({ mapreduce: "page", map: function Map() { emit( this.title, // how to group { name: this.name } // associated data point (document) ); }, reduce: function Reduce(key, values) { //reduce用来处理group出来是多条数据的地方 /* var reduced = {count:0, age:0}; // initialize a doc (same format as emitted value) values.forEach(function(val) { reduced.age += val.age; // reduce logic reduced.count += val.count; }); return reduced; */ return values[0]; }, finalize: function Finalize(key, reduced) { //finalize用来处理group出来是一条数据的地方 return reduced; }, out: { reduce: "test", db: "testdb" } });