Created
May 11, 2015 02:41
-
-
Save hyrmn/0f1824a116cb08f54c3e to your computer and use it in GitHub Desktop.
Batch patching with Raven 2.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var patchCommands = new List<ScriptedPatchCommandData>(); | |
| foreach (var relatedDocument in relatedDocuments) | |
| { | |
| var photo = new Photo | |
| { | |
| Url = imageMetadata.Id, | |
| Title = imageMetadata.Title, | |
| Description = imageMetadata.Description, | |
| SortOrder = relatedDocument.Value, | |
| }; | |
| patchCommands.Add(new ScriptedPatchCommandData | |
| { | |
| Key = relatedDocument.Key, | |
| Patch = new ScriptedPatchRequest() | |
| { | |
| Script = @" | |
| if(!_.has(this, 'Photos')) { | |
| _.extend(this, { 'Photos': []}); | |
| } | |
| this.Photos.RemoveWhere(function(photo) { | |
| return photo.Url === url; | |
| }); | |
| this.Photos.push(newPhoto);", | |
| Values = | |
| { | |
| {"url", imageMetadata.Id}, | |
| {"newPhoto", RavenJObject.FromObject(photo)} | |
| } | |
| } | |
| }); | |
| } | |
| _session.Advanced.GetDatabaseCommands().Batch(patchCommands); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment