Skip to content

Conversation

@tengattack
Copy link

Hi,

I think this PR could help us do some EJSON type & js code for queries like following code:

db.live_statistics.aggregate([
{ '$match': { "time": { '$gte': new Date("$from").valueOf(), '$lt': new Date("$to").valueOf() } } },
{ '$group': { "_id": {
                    $subtract: [ '$time', { $mod: [ '$time', 600000 ] } ]
                }, "sum_online": { '$sum': "$online" }, "time": { '$first': "$time" } } },
{ '$project': {  "name" : "online",  "value" : "$sum_online",  "ts" : { '$add': [ new Date(0), "$_id" ] } } },
{ '$sort' : { "_id": 1 } },
])

@duanjianmin
Copy link

this feature is really helpful, hope it can be merged into the the master branch.
by the way , is this repo support pie chart ? I tried but no success

@tengattack
Copy link
Author

I will have a try for pie chart later

@duanjianmin
Copy link

duanjianmin commented Apr 4, 2019 via email

@tengattack
Copy link
Author

tengattack commented Apr 6, 2019

Yep, it would work by return name field simply (like group by):

For example:

db.userGifts.aggregate([
{ '$match': { "time": { '$gte': new Date("$from"), '$lt': new Date("$to") } } },
{ '$group': { "_id": '$gift_id', "sum_num": { '$sum': "$gift_num" }, "ts": { '$first': '$time' } } },
{ '$project': { "name": "$_id", "value": "$sum_num", "ts": "$ts" } },
{ '$sort': { "value": -1 } },
])

Screenshot 2019-04-06 11 53 30am

BTW, my name is integer type (so it fails to sort for display), you can give it a reasonable name.

@duanjianmin
Copy link

Thanks very much @tengattack , I've tried with pie chart and it is working fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants