Skip to content

Configure camel casing for Chronicle and Arc MongoDB

Configure Chronicle’s projection naming and Arc’s MongoDB naming together so Arc can read the documents Chronicle writes. This guide shows how each backend stores camelCase fields and keeps collection names aligned.

Store read-model data with camelCase field names, and keep Chronicle and Arc’s MongoDB integration agreeing on every field and collection name.

The stored field names start with the names declared in your read model. C# properties use PascalCase by convention; Kotlin properties, Java record components and TypeScript fields usually use camelCase.

A naming policy translates those declared names into storage names. Chronicle’s projections and Arc’s MongoDB integration must agree on both fields and collections. Otherwise, Arc can query a different collection or read documents whose fields do not match its model.

  • An application using Arc with its MongoDB integration, and Chronicle for projections. If you need the initial setup, choose your backend from Arc backends.
  • For C#, the Cratis meta package setup (AddCratis() and UseCratis()).
  • Access to the MongoDB database where Chronicle stores the projected read models, so you can check the result.

Choose your backend in the example below. Apply the naming configuration at startup, before writing data: changing a policy does not rename existing fields or move existing documents to a new collection.

var builder = WebApplication.CreateBuilder(args);
builder.AddCratis(
configureArcBuilder: arcBuilder => arcBuilder.WithMongoDB(
configureMongoDB: mongoBuilder => mongoBuilder.WithCamelCaseNamingPolicy()),
configureChronicleBuilder: chronicleBuilder => chronicleBuilder.WithCamelCaseNamingPolicy());
var app = builder.Build();
app.UseCratis();
await app.RunAsync();

View C# snippet source on GitHub

Turn on the camel case naming policy in both places: in Arc’s MongoDB integration and in the Chronicle client.

For idiomatic camelCase properties, field names need no configuration. Documents store each property under its declared name, and the Chronicle JVM client has no camel case option.

Collection names need no configuration either. With Arc’s MongoDB integration and the Chronicle starter both on the classpath, Arc’s naming policy also names the collection Chronicle projects each read model into, so a projected User lands in Users, the collection Arc reads. This needs Chronicle.Kotlin 6.10.0 or later, which adds the read-model naming policy Arc supplies. To choose other names, declare your own Arc NamingPolicy bean (it flows through the same way), or a Chronicle ReadModelNamingPolicy bean to name Chronicle’s collections alone. An application that declares its own ChronicleOptions bean sets the policy itself with withReadModelNamingPolicy.

For idiomatic camelCase fields, Chronicle’s TypeScript client writes the names as declared. Set camelCaseMongoNamingPolicy on withMongoDB when your read models must match a C# service that uses camel case: it also camel-cases collection names (User becomes users).

Collection names follow Arc. When withMongoDB is configured, the Chronicle client Arc creates stores each projected read model listed in readModels in the collection Arc reads it from (users with camelCaseMongoNamingPolicy), so no collectionName override is needed. This needs @cratis/chronicle 6.29.0 or later, which adds the read-model naming policy Arc supplies. A read model Arc does not read keeps its identifier as the collection name. If you pass your own client to withChronicle, Arc leaves it alone: set readModelNamingPolicy on its ChronicleOptions yourself.

withMongoDB’s database must match the event store name, because Chronicle writes the default namespace’s read models to a database named after the event store.

With this setup:

  • Chronicle projections write read-model fields in camelCase.
  • Arc’s MongoDB integration reads and writes the same camelCase field names.
  • A property declared as EmailAddress in C#, or emailAddress in Kotlin, Java or TypeScript, is stored as emailAddress.

Run a command that produces an event for your read model, then wait for the projection to update it. Inspect the resulting MongoDB document and check that EmailAddress in C#, or emailAddress in the other backends, is stored as emailAddress.

Query the same read model through Arc and check that the value is populated. If the query returns no documents or leaves fields unset, compare the stored collection and field names with the names your backend expects. A naming mismatch can produce those results without an error; also check whether existing documents still use the previous naming policy.