Projections c# api

Hi,

So far got the server working (run as admin), and got it to save events to a stream, and load events from a stream.

Been meaning to have a play around with it since going to the skills matter launch.

I’m looking for some examples of projections, and how can use the C# API to read from a projection.

Sounds like can use a projection to read from streams and create another stream, is this the way to do it?

Scenario

Say I was recording events on certain actions users were performing.

And I wanted to know how many of each type of these actions a user had done.

How could I do this?

I imagine I would have a stream per user.

And thinking there must be a better way than loading the events in and counting how many of each type there are, but finding a lack of documentation.

And if I wanted to know how many each type of these action a user had done on different days (e.g. multiple events of the same type done on the same day would could as 1)

Should I be doing this outside of Event Store? And recording the last event id that I had processed for a user, and just replay new events?

Or does projections fit in?

Just trying to get an overview of how Event Store fits in for my scenario.

Kind Regards

Ian

Sorry for the delay in replying to this - it might be worth taking a look at the latest version on dev (which will be merged to master at some point this week).

You can do this using a projection, either inside the event store, or outside if you host it yourself and subscribe either to individual streams or use the ReadAllEvents* methods.

I’ll post an example of the JS you can use for doing this with a projection shortly.

The projection you want would look something like:

fromAll().foreachStream().whenAny(function(state,event) {

//filter out system streams

if(event.streamId.indexOf("$") != 0)

{

var type = event.eventType;

//probably dont want to log types like $stream-created

if(type.indexOf("$") != 0)

{

if(state[type])

{

state[type]++;

} else {

state[type] = 1;

}

}

}

return state;

});

You can then access the stats for a user over http by:

http://localhost:2113/projection/{projection name}/state?partition={your user stream id}