"result": "post_total",
"timeMillis": 9,
"counts": {
"input": 4,
"emit": 4,
"reduce": 2,
"output": 2
},
"ok": 1,
}
The results show that, the total of 4 documents have been connected to the query (status: "active"), the map function emits 4 documents with key-value pairs and ultimately reduce the function of mapped Documents with the same key go in 2.
To see the results of this mapReduce query, you use the find operator:
> db . posts . mapReduce ( function () { emit ( this . user_id , 1 ); }, function ( key , values ) { return Array . sum ( values )}, { query :{ status : "active" }, out : "post_total" } ). find ()
The above query provides results indicating that both users tom and mark have two posts in the state that is active.
{ "_id" : "tom" , "value" : 2 } { "_id" : "mark" , "value" : 2 }
In the same manner, MapReduce queries can be used to build complex Aggregation queries. The use of custom JavaScript functions makes using MapReduce more flexible and powerful.
According to Tutorialspoint
Previous article: ObjectId in MongoDB
Next article: Text Search in MongoDB