оригинальная коллекция:
{
"_id" : ObjectId('xxxxxxxxxxxxxxxx'),
"userId" : ObjectId('yyyyyyyyyyyyyyyy'),
"urlId" : ObjectId('zzzzzzzzzzzzzzzzzz')
},
{
"_id" : ObjectId('uuuuuuuuuuuuuuuuuu'),
"userId" : ObjectId('aaaaaaaaaaaaaaaa'),
"urlId" : ObjectId('zzzzzzzzzzzzzzzzzz')
}
выделяют:
emit(this.urlId, {userId: this.userId, visitCount: this.visitCount});
уменьшить:
function(key, values) {
var visitCount = 0;
var userVC = new Array();
values.forEach(function(doc) {
NOT SURE WHAT TO PUT HERE TO ACHIEVE DESIRED OUTPUT COLLECTION
});
return {urlId: key, userVC: userVC};
};
желаемый набор выходных данных MR:
{
"_id" : ObjectId('zzzzzzzzzzzzzzzzzzzz'),
"value" : {
"urlId" : ObjectId('zzzzzzzzzzzzzzzzzzzz'),
"userVC" : {
ObjectId('yyyyyyyyyyyyyyyy') : <total visit count for this userId on this urlId>,
ObjectId('aaaaaaaaaaaaaaaa') : <total visit count for this userId on this urlId>
}
}