simple online nosql database database with REST API and MongoDB queries
  • Features
  • Docs
  • Blog
  • Templates
  • Pricing
  • Contact
  • Sign Up
  • Log In

Blog

 The latest news and articles about restdb.io  

Database templates!
Don't forget to visit our template catalog! It's the fastest way to get up and running with a restdb.io database. View templates »

NoSQL aggregations made simpler

by Jon Erik Solheim
|
Howto|API|
  • Share on Facebook
  • Tweet
  • Add to Pocket
  • Share on LinkedIn
  • Send email

An aggregation processes data records and return computed results. With aggregation, you can group values from multiple documents together, and then perform a variety of operations on the grouped data to return a single result. It's perfect for creating reports or gaining more insight from your data.

If you've used MongoDB aggregations, you probably think this is difficult right? 

We'll show you how simple it can be with restdb.io.

Aggregation in restdb.io queries

Lets say that you've created a data collection with Players. And you have scores and categories on each player. With a simple query you can search, group and aggregate data. 

The example below shows how to get all players with a score > 900, grouped by their category with the average score in each category:

https://mydb.restdb.io/rest/players?h={"$groupby":["category"],"$aggregate": ["AVG:score"]}&q={"score":{"$gt": 900}}
 

The query above would return a JSON structure like this:
{
  "doloribus": {
    "score": 981
  },
  "explicabo": {
    "score": 942.5
  },
  "possimus": {
    "score": 937
  },
  "et": {
    "score": 964.6
  },
  "accusantium": {
    "score": 953
  },
  ...

The following table shows the new aggregation functions available in restdb.io. They are appended to restdb.io REST queries in the "h" (hint) parameter as follows.

FunctionFormatCommentExample
Min $MIN:field Returns object h={"$aggregate":["MIN:score"]}
Max $MAX:field Returns object h={"$aggregate":["MAX:score"]}
Avg $AVG:field Returns value h={"$aggregate":["AVG:score"]}
Sum $SUM:field Returns value h={"$aggregate":["SUM:score"]}
Count $COUNT:property Returns value with chosen property name h={"$aggregate":["COUNT:nplayers"]}
Groupby $groupby: ["field", ...] Returns "groupkey":[array] h={"$groupby":["category"]}
Groupby (dates) $groupby: ["$YEAR:field", ...] Predefined values for: $YEAR, $MONTH, $DAY, $HOUR, $SEC h={"$groupby":["$YEAR:registered"]}
Groupby (dates with formats) $groupby: ["$DATE:format", ...] Format strings for: ss, hh, mm, dd, MM, YY. All formats at momentjs.com h={"$groupby":["$DATE.MMM:registered"]}
Grand totals $aggregate-grand-total: true Recursive aggregation functions of groups h={"$groupby":["category"], "$aggregate": ["AVG:score"], "$aggregate-grand-total": true}

For examples and more, continue reading in our docs section.
  • Share on Facebook
  • Tweet
  • Add to Pocket
  • Share on LinkedIn
  • Send email

All Posts


Search

Topics

  • API
  • Authentication
  • Case study
  • Features
  • Howto
  • Integrations
  • Newsletter
  • Productivity
  • Prototyping
  • Tutorials
  • User

restdb.io is a fast and simple NoSQL cloud database service. With restdb.io you get schema, relations, REST API and an efficient multi-user admin UI for working with data.

Our customers use it for backends, business databases, API-first CMS, data collection and much more. It is easy to get started with the free development plan.

Start Building »

  • Site Links
  • Home Page
  • About Us
  • Contact
  • Blog
  • Templates Catalog
  • Cloud Service
  • Features
  • Pricing
  • Terms & Conditions
  • Privacy Policy
  • Sign Up »
  • Documentation
  • Overview
  • Getting Started
  • Coding against the API
  • Utils
  • Security and Admin
© 2025 restdb.io