Multiple projections emitting to the same stream detected

Hi All,

I have a problem with 2 projections linking events to one stream. Is it possible in EventStore at all?

Used projections:

1:

fromStream(‘Devices’)

.when({

$any : function(state, ev) {

linkTo(‘User-’ + ev.metadata.userID, ev);

linkTo(‘Device-’ + ev.data.id, ev);

}

})

2:

fromStream(‘DeviceLinks’)

.when({

$any : function(state, ev) {

linkTo(‘User-’ + ev.metadata.userID, ev);

linkTo(‘Device-’ + ev.data.parentId, ev);

linkTo(‘Device-’ + ev.data.childId, ev);

}

})

Error received:

Multiple projections emitting to the same stream detected. Stream: ‘Device-49f657c7-daa7-433b-8cec-cef304d193c9’. Last event projection: ‘7’. Emitting projection: ‘6’

All, that I’m doing is putting two events in Devices stream and one event to and DeviceLinks that should link them. I’m trying to achieve that in stream Device-guid i would see events like: DeviceCreated, LinkCreated, etc.

Cheers,

Karolis

You cannot have multiple projections writing to the same stream. We have discusses a run with scissors mode for this but if you have multiple writing to the same stream then we cannot provide idenpotency for you.

btw you are writing into only 2 streams? Might it be better to write into multiple streams to start with like device-{guid} then use an indexed projection to handle the linking?

Cheers,

Greg

Thanks for swift reply!

There will be many (10+) streams.

So it’s better to write events directly to the corresponding streams without any linking in ES?
Then there would be many identical events through streams.

For example instead of single DeviceLink event system should write 3 identical events in **DeviceLink, Device-{parentId}, **Device-{ChildId}.

All i want to do is to see all Events somehow linked to single device.

When writing in you are almost always better to write to N streams. You could then write your projection with a pattern match based on event type (will see from all streams) or using a fromategorycategory. If you give a bit more about your problem I can provide more information.