Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional patch requests in RavenDB

How do I patch a document in RavenDB conditionally. The below code just patches all documents of type patron to Middle Initial = JJJ. I also would like to do this per condition.. for example .. do the same patch for the same Patrons documents types.. but for only those that have City ="New York"

store.DatabaseCommands.UpdateByIndex("Raven/DocumentsByEntityName",
                                      new IndexQuery { Query = "Tag:Patrons" },
                                      new[]
                                        {
                                             new PatchRequest
                                                 {
                                                     Type = PatchCommandType.Set,
                                                     Name = "MiddleInitial",
                                                     Value = "JJJ"                                                           
                                                 }
                                            }, allowStale: false);
like image 644
ZVenue Avatar asked Jan 23 '26 01:01

ZVenue


2 Answers

ZVenue, You do it using:

store.DatabaseCommands.UpdateByIndex("Patrons/ByCity",
                                      new IndexQuery { Query = "City:\"New York\"" },
                                      new[]
                                        {
                                             new PatchRequest
                                                 {
                                                     Type = PatchCommandType.Set,
                                                     Name = "MiddleInitial",
                                                     Value = "JJJ"                                                           
                                                 }
                                            }, allowStale: false);

Where the Patrons/ByCity index is defined as:

from p in docs.Patrons select new { p.City }
like image 111
Ayende Rahien Avatar answered Jan 24 '26 21:01

Ayende Rahien


EDIT: It seems that I've been wrong with this answer, because Ayende explains a way how to do it in his answer.

This is something that cannot be done at the moment. However, Matt Warren has implemented something based on IronJS to do this stuff. I don't know when and if it will become part of the main product, but you can certainly use his Github repo if you really need it.

Instead, I suggest you either patch the documents on your own or don't denormalize the data and use .Include() instead if that's applicable in your case.

like image 28
Daniel Lang Avatar answered Jan 24 '26 23:01

Daniel Lang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!