How to do analytic queries on documents?

Suppose I have modeled a cart with items using document models for the actual cart and cart items and a relation between them. A cart item has a product with a category and a value in this example.

In my use case I would like to know the total value per category of a specific cart.

How can I run such analytic queries on these documents?

I know a CDM could be used to get hold of the whole cart. But in my case I am specifically missing something like a “group by” functionality that could be used to find cart items with matching cateories.

Hi @andreas-fresh-mesa

If you have already modeled a CDM, would it be sufficient to then model an approriate Computation Rule on the CDM to compute the filtered value?

You can use the Having operator to filter the FieldList. This is described in:

Mostly yes. The missing piece here is that I would need a separate filter for all the categories being present in the items of the cart which would basically end up if in the questions if computations are able to create repeats (which is not possible as far as my understanding is).

True, you can’t use a computation rule to create rows in a repeat.

You can add some Additional Link Fields to the relationship as I’ve modeled a n:n relationship. This means I can calculate the subtotal for each link based on the category used in this link.

This does create some redundant information as this subtotal is calculated for each link and not for each category but you should be able to filter these values once you have them.

I’ve highlighted your question to my technical colleagues so that they can have a look at it too.