Better patching API for RavenDB: Creating New Documents
Join the DZone community and get the full member experience.
Join For FreeA while ago we introduced the ability to send js scripts to RavenDB for server side execution. And we have just recently completed a nice improvement on that feature, the ability to create new documents from existing ones.
Here is how it works:
store.DatabaseCommands.UpdateByIndex("TestIndex", new IndexQuery {Query = "Exported:false"}, new ScriptedPatchRequest { Script = script } ).WaitForCompletion();
Where the script looks like this:
for(var i = 0; i < this.Comments.length; i++ ) { PutDocument('comments/', { Title: this.Comments[i].Title, User: this.Comments[i].User.Name, By: this.Comments[i].User.Id }); } this.Export = true;
This will create a set of documents for each of the embedded documents.
Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Application Architecture Design Principles
-
How Web3 Is Driving Social and Financial Empowerment
-
What Is Envoy Proxy?
-
Building a Flask Web Application With Docker: A Step-by-Step Guide
Comments