Mongo Documentation
We use find and aggregrate mongo query types. You can read up on how the mongo aggregation pipeline works here.
Taking our event from earlier, let's write some queries to display some of the data we were seeing.
Requests By Tag Name in Last X Weeks
Query
[ { "$match":{ "tags.category":"#category#", "tags.action": "#action#", "date":{ "$gte":"#gte#", "$lte":"#lte#" } } }, { "$project":{ "action":"$tags.action" } }, { "$group":{ "_id":"$action", "count":{ "$sum":1 } } } ]
Click the image to increase the size.
Result
{ "utilities": [ { "_id": "Start", "count": 4 } ] }
Actions in Specific Category
Query
[ { "$match": { "tags.request.answerSpace.name": "#answerspace#", "tags.request.answerSpace.form": { "$exists": true }, "date": { "$gte": "#gte#", "$lte": "#lte#" } } }, { "$project": { "form": "$tags.request.answerSpace.form" } }, { "$group": { "_id": "$form", "count": { "$sum": 1 } } } ]
Click the image to increase the size.
Result
{ "utilities": [ { "_id": "Stop", "count": 2 }, { "_id": "Start", "count": 4 } ] }