Eventstore: Question: How can I get a list of all categories in GetEventStore?

Created on 26 Sep 2017  路  6Comments  路  Source: EventStore/EventStore

Sorry if it is a stupid question. What I want is:

From streams like these:

  • sales-sale102
  • sales-sale103
  • sales-sale104
  • users-8989
  • users-8990

Get somethig like this:
[ "sales", "users"]

I already asked this in the Google Groups and even in Stackoverflow, but with no response.

Most helpful comment

That is faster. Good idea :)

$ce-category just "groups" all events from the same category. So $ce-users will contain link events to all events in users streams. Its very useful for projections and when you want to create subscriptions that only target one aggregate root type.

All 6 comments

It is possible to write a transient projection (Query), or a regular projection in EventStore. This might be a good starting point:

fromAll().
when({
    $init: function() {
        return {
            categories : []
        }
    },
    $any: function(s, e) {
        var category = e.streamId.split("-")[0];

        if (s.categories.includes(category))
            return;

        s.categories.push(category);
    }
})

I thought that there is a built-in thing like $ce-category. But thanks @nissbran!

Would it be faster to go fromStream('$streams') instead of going fromAll()?

That is faster. Good idea :)

$ce-category just "groups" all events from the same category. So $ce-users will contain link events to all events in users streams. Its very useful for projections and when you want to create subscriptions that only target one aggregate root type.

Hi, I implemented the same projection, but having truncated events, these events do not have any streamId property. I can check if streamId is defined, but still if first event of all streams of a category have been truncated, I do not get the category in the projection.

I tried looking at event object for truncated events, everything is null or empty...but we can still see a Name (nothing else) when looking at $streams in the UI. Also, we can get the Name string with C# API, from ResolvedEvent.Event.Data. why is there nothing in parameters given to handle functions ?

Thanks for your feedbacks.

Hello, sorry I tried with fromStream('$streams')...it works with fromAll(). Still, I don't understand why there is some properties in events with fromAll and nothing with fromStream('$streams') ?
Also, looks like fromAll return only events from non system streams, right ? (a bit vague in doc "Selects events from the聽$allstream")
I would be happy to PR docs with answers :).

Was this page helpful?
0 / 5 - 0 ratings