I just want to get sum data for 7 days using nodes & mongodb.
Mysql and Oracle is fine but mongodb does not show me the result that I wish.
find condition :
var reference_day = moment().add(-7, 'days').toDate();
var option = {regist_day: {'$lt': reference_day},
'$or':[{country:'uk'},{status:'usa'}]}
I don't know how to apply group by or sum in mongodb, It took so many times to understand for this.
Finally I've learned that "aggregate" can resolve my case.
However the result's something wrong. I can't get the data as I think it is, but mongodb lose some of the data.
this.aggregate([
{
$match:option
},
{
$sort:{
regist_day:-1
}
},
{
$limit:20
},
{
$skip:20 * (page - 1)
},
{
$group:{
_id:'$userid',
sum: { $sum : '$price'},
cnt : { $sum : 1}
}
}
This implementation has some problems with normal values but sometimes in many cases with loss of data. What do you think I am doing wrong?
I just thought that I suspect "$or" condition the item is strange, but it is not clear.