Group / MapReduce in moongoose 3.6.15
I have model Record which looks like this:
{
_id: '52278952a4bb5a7415000002',
owner_id: '52278952a4bb5a7415000001',
state: 'some_string'
}
I want to GROUP records collection by owner_id where Record.state =
'some_string' and count them for each owner. In other words I want to
count all records with state = 'some_string' for each owner (specified in
record as owner_id). How I can accomplish this? I searched in google for
mongoose group and mongoose map/reduce but couldnt find anything that I
would understand - and map reduce as I know puts results to new collection
and I dont want to do this. I cant find any information in mongoose docs.
Other examples contains some strange keywords in query like $project etc.
Can anyone provide me good working example to this problem? It should be
simple to do this I guess... I found out that there is method
Model.agregate(...) method but cant find how to use it.
I use mongoose 3.6.15.
No comments:
Post a Comment