I am trying to work out the map functions and reduce functions for the following case:
documents:
{
"_id" : "1_A",
"key1": 10,
"key2": 10
}
{
"_id" : "2_A",
"key1": 2,
"key2": 3
}
{
"_id" : "1_B",
"key1": 20,
"key2": 20
}
{
"_id" : "2_B",
"key1": 1,
"key2": 0
}
etc.
expecting to have: the sum of each key (key1, key2... keyn) in all documents with id ends with "_A", "_B" ... "_Z" individually.
in this case, expecting to have sumA: "key1":12, "key2":13. and sumB: "key1":21, "key2":20;
I have been working on the map function(doc), it seems like to me that the it is only to deal with one document which specified as the "doc" value at a time.
Is there anyway to achieve the result as expected? is there anyway like SQL join???