Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do projection from a category?

Tags:

eventstoredb

I'm currently storing events in the following format mycategory-mytype-uniqueid. What I have understood after reading various posts on the web I should get a category called mycategory doing that. I have written :

fromCategory('mycategory')
  .foreachStream()
  .when({
    $init: function(){
      return {number: 0};
    },
    $any: function(state, ev){
      linkTo('mynewstream', ev);
      return {number: state.number};          
    }      
  });

I now expect to get a stream mynewstream as well as a result with a variable number, but I got neither. So what am I missing?

like image 446
Tomas Jansson Avatar asked Jun 05 '14 10:06

Tomas Jansson


2 Answers

I want to add to Alexey Zimarev's commment, because I ended up here when googling the same problem, but I have too little reputation so I'll have to put this comment in an answer.

Like Tomas Jansson writes in his own answer, the "$by_category" standard projection now comes with the

first
-

configuration.

And just like Alexey Zimarev writes in his comment, the standard projections are not STARTED automatically, even if you configure EventStore to run all projections.

So, in order to start EventStore with all projections enabled and started, you need something like this in your yaml config file:

RunProjections: All
StartStandardProjections: True

Or, if doing configuration by command line options, use:

EventStore.ClusterNode.exe --run-projections=all --start-standard-projections=true
like image 157
Otto Dandenell Avatar answered Jan 02 '23 23:01

Otto Dandenell


I figured out how to do it. By default eventstore creates categories based on the last word after splitting on -. If you want to change this you have to modify the $by_category projection. In that projection you specify what character to split at if you only specify one row, but if you want to use the first row as category you have to update the file to something like:

first
-

That tells eventstore to take the first word after splitting on - as the category for the events.

like image 36
Tomas Jansson Avatar answered Jan 02 '23 23:01

Tomas Jansson