"orders by shipment date" as a projection, but shipment date can change

Hi there

We want to use ESDB to model our order entity. An order has a shipment date, which can change n times after the order has been placed. The events are called orderCreated and orderDeliveryDateChanged resp. and both contain a shipment date. In order to show a list of all orders for a given date in a backoffice application we created a projection that partitions by shipment date:

fromCategory('orders').partitionBy(e => e.data.shipment && e.data.shipment.date).when().outputState()

Now because the partitioning happens based on the events, not an aggregated state, an order which had its shipment date changed n times will show up in as many streams, not in only one.

Is there a way to partition a projection based on an aggregated state? Are projections the right approach here?


Could you use fromStream(‘orders’) instead, so you will get partition based on each aggregate or do roderCreated and orderDeliveryDateChanged belong to different aggregates?
If that is the case, you could use fromStreams(‘orders’, and build the partition (like in your example)

Honestly, I would subscribe to $all, filter those two events by type and project to a state-based store like MongoDB. If you’re only interested in showing the latest state, I don’t see any value in emitting more events for that just to read the state. Plus, you get full control on where and what you project.