2

mongos group 関数で行うように、mongos mapreduce で条件を指定するにはどうすればよいですか。

私のデータは

{lid:1000, age:23}, {lid:3000, age:23}, {lid:1000, age:24}. 

値が 1000 のふたのみを放出したいemit(this.lid, this.age). . しかし、これはすべての値を発行します。ここで条件をつけたい。map reduce に何か手段はありますか? reduce 関数で if 条件を使用してフィルタリングしようとしましたが、機能しません

4

2 に答える 2

9

パラメータでそれを行うことができqueryます。ドキュメントページから: http://www.mongodb.org/display/DOCS/MapReduce#MapReduce-Overview

db.runCommand(
 { mapreduce : <collection>,
   map : <mapfunction>,
   reduce : <reducefunction>

   --> [, query : <query filter object>] <--

   [, sort : <sorts the input objects using this key. Useful for optimization, like sorting by the emit key for fewer reduces>]
   [, limit : <number of objects to return from collection>]
   [, out : <see output options below>]
   [, keeptemp: <true|false>]
   [, finalize : <finalizefunction>]
   [, scope : <object where fields go into javascript global scope >]
   [, verbose : true]
 }
);
于 2011-05-05T07:05:17.780 に答える
1

マッピング関数は JavaScript 関数です。次のように、必要なことは何でも実行できます。

if (this.lid == 1000) emit(whatever);
于 2011-05-05T07:00:24.540 に答える