Awesome RavenDB Feature: Eval Patching, Part II–Denormalized References
Join the DZone community and get the full member experience.
Join For FreeI mentioned yesterday that I am keeping the best for today. What I am going to show you is how you can use Eval Patching for keeping track of denormalized references.
In this case, we have Users & Posts. Each Post contains a UserName property as well as the user id. When the user changes his name, we need to update all of the relevant posts.
Here is how you can do this:
store.DatabaseCommands.UpdateByIndex("Posts/ByUser", new IndexQuery{Query = "UserId:" + userId}, new AdvancedPatchRequest { Script = @" var user = LoadDocument(this.UserId); this.UserName = user.Name; " });
And this is a really simple scenario, the options that this opens, the ability to load a separate document and modify the current document based on its value is really powerful.
Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Managing Data Residency, the Demo
-
Integrating AWS With Salesforce Using Terraform
-
MLOps: Definition, Importance, and Implementation
-
What Is mTLS? How To Implement It With Istio
Comments