Writing mongo queries for the first time can be quite intimidating - luckily however, the analytics console provides the query playground, for users to build out and test their own custom queries.
Query Playground
The query playground will let you choose from your project queries to run over the collector you'll select just afterwards. Users will then be prompted to fill in the values required by the query, before being able to execute it. This emulates how a query would be set up within the dashboard, and is extremely helpful for testing and prototyping purposes.
The output is essentially your raw JSON data, which is what is absorbed by the API powering the visuals behind your analytics graphs.
Before you begin, it's important to know the shape and structure of the event you're trying to query, especially if this is your first time using this feature.
Luckily, we have can create a query for that:
Code Block | ||||
---|---|---|---|---|
| ||||
[ { "$sort":{"date":-1} }, { "$limit":"#n#" } ] |
Start by exiting the playground back to the default query view, and creating a new query called 'Last N events' (or whatever you like, really), by clicking the + button.
Next, copy the code above into the Params section. This will be the body of your query, and all your logic should go in here.
This is an aggregate query, which should be reflected in the Type drop down section. This will place a wrapper around the query when it's ran. A find option is available also.
Note the 'limit' value:
"$limit":"#n#"
The two hash symbols enclose a value that needs to be passed in by the user. Here, it is the value n.
This is a fairly simple query, and probably won't get you too far in terms of displaying graphs.
Our Query Examples and Tips section will go more in to detail on different query types and how to display the data you wish to see.
Next up, we'll show you how you can test your queries and analyse their output, using the Query Playground.
Next Step
...