How to pass aggregate query while embedding MongoDB chart to pre-process the data?

Hi @Rahul_Chouhan1 -

Right now there are a few limitations in what you can do here:

  1. With the embedding SDK, you can only pass in a filter (which is wrapped in a $match stage), no other stages can be injected.
  2. The full aggregation pipeline is generated in a specific order as documented at Backing Aggregation Pipeline — MongoDB Charts

This means that while it is possible for you to pass in your ObjectID query through the SDK, it will be inserted after the query bar query, the $project and $group stages will execute before the filter (which probably isn’t what you want).

Grouping and projections are automatically generated when you encode fields, so perhaps you could find a way to make this work. We do realise the current behaviour can be limiting for advanced scenarios, and we hope to find ways to make it more flexible in the future.

Tom

1 Like