Projection link per aggregate root

Hello,

If I understand it correctly, it should be possible to create projection, which show values of aggregate root. I have this sample code:

var ContactId = Guid.NewGuid();

var ContactCreated = new ContactEvent(new

{

Id = ContactId,

FirstName = “Peter”,

LastName = “Snobelt”

}, “ContactCreated”);

var ContactUpdated = new ContactEvent(new

{

Id = ContactId,

FirstName = “Petr”,

LastName = “Snobelt”

}, “ContactUpdated”);

using(var connection = new EventStoreConnection(new System.Net.IPEndPoint(ipaddress, 1113))) {

connection.AppendToStream(“Contacts”, -2, new[] { ContactCreated, ContactUpdated });

Console.WriteLine(“Stored”);

}

``

I expect it should be possible to create 2 projections, first which return all contacts (useful for grids) and second which return values per contact (used on details). But I don’t know how to create these projections,especially second projection (I expect it should be available on url which contains ContactId).

Is there any sample of these 2 projections? I try to look at chat sample, but it looks it replay events on client and not on server.

Maybe I just did not understand exactly how to work with projections :slight_smile:

Thanks

Petr,

There are two ways how one can consume projection results.

  1. Current projection state can be retrieved with an http request to the “/projection/{name}/state”
2) The last available state of a persistent projection can also be read as the last event from the $projections-"+projectionname+"-state" stream. Persistent projections publish "stateUpdated" events into this stream.

Projections with foreachStream() maintain separate state for each stream they process.  As of today they do not support  "/projection/{name}/state" http requests (this is on priority list)
However, you can still retrieve the most recent state for persistent foreachStream() projections from streams named after this pattern: 
$projections-{projection_name}-{aggregated_stream_name}-state"

-yuriy

Petr,

Now, it is possible to retrieve a state of any projection partition via http with

“/projection/{name}/state?partition={partition}”

where partition is a stream name in case of foreachStream().

Pushed to dev for now.

-yuriy

Petr,

You can now choose a name of the stream to write StateUpdated event to.

The following statement configures a projection to write events to the stream named “state-updates”.

options({
stateStreamName: ‘state-updates’,
});

In case of a forteachStream() projection the stateStreamName options requires {0} placeholder which will be replaces with the currently processed stream name.

-yuriy