3
我需要得到一定值的出現次數的集合中,像這樣的:計數的GroupBy用帆 - 蒙戈
[
{author: 'Diego', name: 'This is a great post', date:'03/13/78'},
{author: 'Raul', name: 'Recipe for success', date:'02/03/99'},
{author: 'Diego', name: 'Having too much fun', date:'01/01/77'},
{author: 'Diego', name: 'Another post by me', date:'10/9/99'},
{author: 'Diego', name: 'Mi first post', date:'01/01/73'},
{author: 'Mariano', name: 'Mi best post', date:'01/01/95'},
]
我想水線find()方法返回參數:
[
{author: 'Diego', count: 4, date: '01/01/73'},
{author: 'Raul', count: 1, date: '02/03/09'}
]
到目前爲止,我能夠得到的一切除了計數,這一點:
Model.find({
where: {author: {'!': 'Mariano'}},
groupBy: ['author'],
min: ['date']
// and count?!?!?!
}).exec(function(err, items) {
//do something with items.
});
我試過用「sum:['1']」但只給了我一個名爲「1」的屬性,每個結果行的值爲0。