Changing stream name in production

So I have some data in the production event store that needs to be preserved, but I need to change the stream name from ‘Account’ to ‘Client’. How do I do this? I saw somewhere on this group that ‘emit’ was the solution but it didn’t really talk about how? Could someone explain?

Hi Denny,

Emit is a projection function that writes an event to a stream, you can find its signature at the bottom of this page: http://docs.geteventstore.com/projections/4.0.0/user-defined-projections

To rename a stream, you could create a projection from the Accounts stream, and in that projection emit the events to the Client stream.

A very simple example of this would be:

fromStream(“Account”)

.when({

$any: function(s,e) {

emit(“Client”, e.eventType, e.data, e.metadata);

}

});

Please note that you will need to set emit enabled to true when you create the projection for this to work.

Hi Denny,

So, whenever I want to change anything in existing events, I'll do a
blue/green deployment with copy/transform. I.e. set up a new cluster,
with new names and whatnot, have that subscribe to existing cluster
and do whatever changes I need while writing to the local ES. It's a
really powerful way to go about it, but as always it will depend on
how you've set things up whether this is possible for you or not.

/Rickard

Does that preserve the same format - ?? I created the projection and nothing was visible in the stream browser. Then I tried fromStream("$ce-Account’) and it sort of worked, except it lumped everything into a stream called Client instead of many streams called Client-

it depends what you put in the emit as stream name :wink:

Ah, so I just need to concat emit(“Client-”, e.data.EntityId…

erm “Client-” + e.data.EntityId

Yes, you are creating the stream name and can make it whatever you want.

That’ll work, thanks. Now to update my deserialization process to handle the variance in expected types…

So I found that this causes a different problem. Now the $ce- project is faulting because there are multiple things writing to this stream. Is this a real problem and is there a way to straighten this out?

only one projection can write to a stream

Right, I get that, but I don’t have any projections to begin with. Everything is basically default settings. How would I find the offender?

Do you write in your code to these streams?

Hi Denny,

  1. What version of Event Store is this?

  2. Can you provide us with the exact error message?

  3. Can you provide us with the events in the stream $projections-$all

e.g

curl -i -d@create_by_category.json “http://localhost:2113/streams/%24projections-%24all” -H “Content-Type:application/vnd.eventstore.events+json” -u admin:changeit

``

Yes, I in this particular case, I have a single instance of a single project in code that writes to this stream through a single instance of IEventStoreConnection.

projections do not allow outside clients to write to the same stream, can you clarify if you are doing this?

Version: 3.9.3
Message: Multiple projections emitting to the same stream detected. Stream: ‘$ce-NotificationAccount’. Last event projection: ‘2’. Emitting projection: ‘15’

  • not sure if that query is correct. It just returns errors

I just went back and reviewed the code. A couple things, I don’t write to any thing as $ce-; I write to -

$ce-NotificationAccount is what it’s complaining about, but that project has been deleted. That was a a project created to move events from NotificationAccount- to NotificationClient- following a conversation to you.

Another conversation we had, dealt with creating a replication service that would listen to events in production and write them back to Dev. That service is not currently running.

I do apologise, that query is incorrect. I copy/pasted incorrectly.
Corrected query below

curl -i “http://localhost:2113/streams/%24projections-%24all?embed=tryharder” -H “Accept:application/vnd.eventstore.events+json” -u “admin:changeit”

``

and then if you don’t mind issuing the following query

curl -i "http://localhost:2113/projections/any

``