MongoDB データベース コレクションの 1 つで単純な map/reduce 関数を作成しようとしています。データを取得しましたが、間違っているようです。地図の部分がわかりません。このように IF/ELSE を使用できますか?
アップデート
ファイルを所有している作成者の数を取得したい。つまり、アップロードされたファイルを所有している作成者の数と、ファイルを所有していない作成者の数です。
コレクション内のオブジェクトは次のようになります。
{
    "_id": {
        "$id": "4fa8efe33a34a40e52800083d"
    },
    "file": {
        "author": "john",
        "type": "mobile",
        "status": "ready"
    }
}
map / reduce は次のようになります。
$map = new MongoCode ("function() {
if (this.file.type != 'mobile' && this.file.status == 'ready') {
 if (!this.file.author) {
  return;
 }
 emit (this.file.author, 1);
}
}");
$reduce = new MongoCode ("function( key , values) {
 var count = 0;
 for (index in values) {
  count += values[index];
 }
 return count;
}");
$this->cimongo->command (array (
 "mapreduce" => "files",  
 "map"       => $map,   
 "reduce"    => $reduce,  
 "out"       => "statistics.photographer_count"
)
);