Updating projection definitions
This page describes how to update projection definitions in SerializedSerialized supports updating projection definitions. This is useful if you want to change the projection logic or any other information in the definition.
When you update the logic for a projection definition, Serialized will automatically reprocess all events in the feed. Any existing projection data for the projection definition will be deleted when you update the projection. Projection data will be unavailable until the processing of all events matching the new projection definition has completed. This is to ensure that queries to the projection will return the correct data.
Updating a projection definition
The following example shows how to create, then update a projection definition called orders-by-id
. In the first
version it will only project the OrderPlaced
event, but in the second version it will also remove projections when
the OrderCancelled
event is processed:
// Merge in all data from the OrderPlaced eventvar mergeOnOrderPlaced = newHandler("OrderPlaced").addFunction(Functions.merge().build()).build()// Create the projection definitionprojectionClient.createOrUpdate(singleProjection("orders-by-id") .feed("order") .addHandler(mergeOnOrderPlaced) .build());var deleteOnOrderCanceled = newHandler("OrderCanceled").addFunction(Functions.delete().build()).build()// Update the projection definition (will now handle both OrderPlaced and OrderCanceled)projectionClient.createOrUpdate(singleProjection("orders-by-id") .feed("order") .addHandler(mergeOnOrderPlaced) .addHandler(deleteOnOrderCanceled) .build());