Event store query

How can we query the Eventstore by aggregate root Id?
If I want to retrieve all the events related to an user how can I do that?

By putting all those events in the same stream (eg stream per user)

or when you have cross cutting things you want to query from many streams …

you can write a projection to reindex them based on say the user. Let’s imagine you had metadata with userId in it …

fromAll().when($any :function(s,e) {linkTo(“byuser-” + e.metadata.userId, e)

This will create a stream per user of all events having metadata with a userId associated to that user.

1 Like

Stream per user does it really scale if I have a million users?

Streams are essentially free in eventstore its intended to have many many millions of streams…

btw for a real fun one there is a system I know of that has approaching a Billion yes that’s with a B streams :slight_smile:

That is impressive! BTW I am big fan of you. Watched all your talks on event sourcing.

If I read all events from the partitions, it is just looping through n-items before i could find a event associated for an user. Is it really
efficient[?].

Yes, it is very efficient.

The projection will loop through the “n-items” only ONCE (or AGAIN when you reset), and re-index the matching events into a new stream. You can then subscribe to (or use another projection on**)** the new stream to get the shape of data (i.e. state) you desire.

Projecting from (or Subscribing to) a filtered stream is very efficient.

Hope this helps.

Foluso.