Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7943049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:09:25+00:00 2026-06-04T00:09:25+00:00

I am trying to update a nested collection using the Patch API. More specifically,

  • 0

I am trying to update a nested collection using the Patch API. More specifically, consider the following example – a Posts collection:

{
  "Title": "Hello RavenDB",
  "Category": "RavenDB",
  "Content": "This is a blog about RavenDB",
  "Comments": [
    {
      "Title": "Unrealistic",
      "Content": "This example is unrealistic"
    },
    {
      "Title": "Nice",
      "Content": "This example is nice"
    }
  ]
}

I used the Patch API and Set-based operation docs at http://ravendb.net/docs/client-api/partial-document-updates and http://ravendb.net/docs/client-api/set-based-operations as well as several stackoverflow questions as resources to do a bulk update using set operations and a static index. A requirement is to update the “Title” of a comment only when the previous value was “Nice” and if so, update it to “Bad”.

The static index “NicePosts” is defined as:

Map = posts => from post in posts    
               where post.Comments.Any(comment => comment.Title == "Nice")
               select new {post.Title, post.Category}

The bulk patch update command is:

    documentStore.DatabaseCommands.UpdateByIndex("NicePosts",   
                    new IndexQuery(),                                               
           new[] { new PatchRequest 
                    {   Type = PatchCommandType.Modify,                          
                    Name = "Comments",  
                      PrevVal = RavenJObject.Parse(@"{ ""Title"": ""Nice""}"),
                      Nested = new[]
                              {
                                new PatchRequest {Type = PatchCommandType.Set, Name = "Title", Value = new RavenJValue("Bad") },
                       }  }, allowStale: true);

I have some questions regarding this:

1) Is my structure/syntax for the update command correct?

2) I would like the update to be performed on all the records in the collection. Hence I haven’t defined the query filter in the IndexQuery Query because the “NicePosts” index already returns the appropriate set. However running this command doesn’t update the collection.

3) If I set “allowStale:false” I get a “stale index” error. Before opening my document store session I instantiate the index class and Execute it to persist it to the ravenDB instance. Any ideas whats going wrong here?

Thanks,

EDIT:

Based on ayende’s recommendation changed Patch command to:

 documentStore.DatabaseCommands.UpdateByIndex("NicePosts",
                                         new IndexQuery(),
                                         new[] {
                                                   new PatchRequest {
                                                     Type = PatchCommandType.Modify,
                                                     Name = "Comments",
                                                     Position = 0,
                                                     Nested = new[] {
                                                       new PatchRequest {Type = PatchCommandType.Set, Name = "Title", Value = new RavenJValue("Bad")},
                                                     }
                                                   }
                                                 }, allowStale: false);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:09:27+00:00Added an answer on June 4, 2026 at 12:09 am

    You can’t use the patch command to update values based on the existing value in the array.
    You need to specify the actual position.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using codebrew\backbone-rails in a nested model example (say I have a collection of
I am trying to update a nested has_one model using mongoid but it will
When trying to update a subversion working copy from Netbeans, I get the following
So I'm trying to update an object in my MS SQL 2005 database using
Im trying to update some nested params from a form. I can see that
I'm trying to update a model with nested properties after an edit. The update
I am following alloy-complex-form-examples from github trying to learn nested forms and I just
I am trying to get nested viewflippers set up with the following setup Top_ViewFlipper
I'm trying to get the following SQL statement to work: UPDATE myschema.tableA update_tableA SET
Update edition: So, I'm trying to get this code to work without using scanf/fgets.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.