Ayende @ Rahien

Hi!
My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:

ayende@ayende.com

+972 52-548-6969

, @ Q c

Posts: 09 | Comments: 20

filter by tags archive

Better patching API for RavenDB: Creating New Documents

time to read 2 min | 329 words

A 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.


Comments

Daniel Lang

This helps a great deal with schema migrations. Btw, what happens when we patch lots of documents this way, create new documents along the way and then there is an error and execution stops... is then entire patch operation transactional, or is there any way to make it transactional?

Daniel Marbach

Daniel, Patching API is not transactional.

tobi

It all converges to SQL...

Ayende Rahien

Daniel, Patching is transactional on a single document, yes. That is, if you create a 1000 documents in a patch, and it fails on the 1001 document, it will all go away.

However, it is not transactional over set operations. We pulse the transaction along the way at various points to avoid high memory usage, and that means that stuff that happened for a document in the beginning of the operation will be there if the operation fails for a much later document.

Since documents are independent, and a single document patch operation is transactional, we don't see this as a problem

Comment preview

Comments have been closed on this topic.

FUTURE POSTS

  1. Production postmortem: The case of the memory eater and high load - 3 days from now
  2. Production postmortem: The case of the lying configuration file - 4 days from now
  3. Production postmortem: The industry at large - 5 days from now
  4. The insidious cost of allocations - 6 days from now
  5. Find the bug: The concurrent memory buster - 7 days from now

And 4 more posts are pending...

There are posts all the way to Sep 10, 2015

RECENT SERIES

  1. Find the bug (5):
    20 Apr 2011 - Why do I get a Null Reference Exception?
  2. Production postmortem (10):
    14 Aug 2015 - The case of the man in the middle
  3. What is new in RavenDB 3.5 (7):
    12 Aug 2015 - Monitoring support
  4. Career planning (6):
    24 Jul 2015 - The immortal choices aren't
View all series

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats