Friday, 17 March 2017

Mongo Groupby Aggregate Based on "Key" Not Value

I am stuck with mongo query. I have a mongo collection structure which i can not modify at this time as it is very large data.

I need to carry out some results from the collection , so tried all ways round to get it.

Here is my collection json schema:-

{
    "date": "2017-01-01T00:00:00.000Z",
    "bob":"P",
    "jacob":"P",
    "wilson":"A",
    "dev":"SL"
    },
    {
    "date": "2017-01-02T00:00:00.000Z",
    "bob":"P",
    "jacob":"A",
    "wilson":"A",
    "dev":"SL"
    },
    {
    "date": "2017-01-03T00:00:00.000Z",
    "bob":"P",
    "jacob":"P",
    "wilson":"A",
    "dev":"SL"
    },
    {
    "date": "2017-01-04T00:00:00.000Z",
    "shashikant":"P",
    "jacob":"P",
    "wilson":"SL",
    "dev":"SL"
    }
    ....

As output I am looking for below kind of structure:-

from 1st jan 2017 to 30th jan 2017

    bob      P      17
    bob      A      2
    wilson   P      10
    dev      SL.    1
    .....

I am using loopback for my backend but still i can use normal mongodb query to get the output.

Please help

Thanks in advance.



via BeingExpert

No comments:

Post a Comment