mingo-app / mingo

Found a bug? have a FR ?
60 stars 2 forks source link

Group by and count doesn't work for arrays #470

Closed thiagotsn closed 1 year ago

thiagotsn commented 2 years ago

When trying to use the Group by and count feature for an array record, it's aggregating all records in an empty string. Example:

CleanShot 2022-08-23 at 14 59 10@2x
tothradoslav commented 2 years ago

Thanks for this. Could you please provide more info on where you are using this feature? It could be on a specific field in the documents view or on a column?

column field
thiagotsn commented 2 years ago

Initially I was mentioning the document view. But I just checked with column and it also happens. I just have the issue if it's a field inside an array. I drill down one element of the array and select a field. From there, I try to group by and count for All documents...

tothradoslav commented 2 years ago

OK thanks, will correct it. I see your issue now. Can you send a small example of your doc? Or just a part of it and what you select do group-by-count? Is it an array of strings (or other primitive values) or an array of objects?

tothradoslav commented 2 years ago

Can you send a small example of the doc / array? Is it an array of primitive values (strings, numbers, etc...) or an array of objects?

thiagotsn commented 2 years ago

It's an array of objects. If I select any primitive type inside the object it'll display the values above.

{
  "item": [
    {
      "id": "12345",
      "customer": "JOHN DOE",
      "product": {
        "name": "Product Test",
        "type": "BOOK"
      },
      "quantity": 1
    },
    {
      "id": "54321",
      "customer": "JANE DOE",
      "product": {
        "name": "Product Test 2",
        "type": "PEN"
      },
      "quantity": 1
    },
  ]
}
tothradoslav commented 2 years ago

Thanks. And would you like to group/count the values within the selected document only (so within that array) or within all arrays in all documents of the collection?

thiagotsn commented 2 years ago

I was expecting to group and count all documents in the collection

tothradoslav commented 1 year ago

This now works both on arrays of primitive values and on nested arrays of objects. So you can now groupby and count on something like this for example: photos.0.title (will groupby / count all title in all photos)

tothradoslav commented 1 year ago

This has been resolved in the latest RC release, please check it out and let us know if the solution works as expected:

https://github.com/mingo-app/mingo/releases/tag/v1.13.0-rc1

thiagotsn commented 1 year ago

It's working now. I just tested it. Thanks!

tothradoslav commented 1 year ago

https://github.com/mingo-app/mingo/releases/tag/v1.13.1