MongoDB Query for grouped results

#1

Hi!
Our ultimate goal is to GET all available platforms (Windows, Linux, PHP, Solaris…) from our document database.
Consider this: We have DreamFactory connected to our MongoDB. In this database we have documents with a field named ‘platform’, which holds values like ‘windows’, ‘linux’, ‘php’ etc. Many documents have the same platform value.

The result we want looks like this for example:
    {
      "resource": [
        {
          "_id": "5ca8d9d54a71d055259dba85",
          "platform": "php"
        },
        {
          "_id": "5ca8da304a71d055417e1d4e",
          "platform": "windows"
        },
        {
          "_id": "5ca8da324a71d055417e1d4f",
          "platform": "asp"
        }
      ]
    }

I want to do an API call which returns all available platforms, which is easy:
/api/v2/mongodb/_table/vuln_applications?fields=platform
Problem now is that this query returns for example 1000 documents where platform=windows. I want to group or aggregate it into one per available platform.

I tried to use the “group” field in the API Docs, but that didn’t help:
/api/v2/mongodb/_table/vuln_applications?fields=platform&group=platform

Got any idea on how to achieve this? Sorry if its a bad explanation.

0 Likes

#2

We ended up creating a custom python script in DreamFactory. Still, if there is another way through a normal API call, I’d appreciate if someone posted it.

0 Likes