Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ejson support for mongodb query #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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