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

  • SEARCH
  • Home
  • 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 8287201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:58:19+00:00 2026-06-08T11:58:19+00:00

Using Ravendb (build 960) I am attempting to perform a bulk update on a

  • 0

Using Ravendb (build 960) I am attempting to perform a bulk update on a set of documents to replace a single value in list of strings. I used Google Group Question as base for the code, as the request was the nearly identical, but for some reason they were able to get theirs to work while mine errors out. I have composed the following sample console application to demo the issue.

public class Document
{
    public const string OLD_NAME = "Label A";
    public const string NEW_NAME = "Label B";

    public Document()
    {
        Labels = new List<string> { OLD_NAME };
    }

    public string Id { get; set; }
    public IList<string> Labels { get; set; }
}

public class Document_By_Labels : AbstractIndexCreationTask<Document>
{
    public Document_By_Labels()
    {
        Map = leads => from doc in leads select new {doc.Labels};
    }
}

internal class Program
{
    private static void Main(string[] args)
    {
        IDocumentStore store = new DocumentStore
        {
            Url = "http://localhost:8081",
            DefaultDatabase = "RavendbPatchStringListTest"
        }.Initialize();
        IndexCreation.CreateIndexes(typeof (Program).Assembly, store);

        using (IDocumentSession session = store.OpenSession())
        {
            var s = new Document();
            session.Store(s);
            session.SaveChanges();

            var d = session.Load<Document>(s.Id);
            var m = session.Advanced.GetMetadataFor(d);
        }

        store.DatabaseCommands.UpdateByIndex("Document/By/Labels",
                                             new IndexQuery {Query = string.Format("Labels:\"{0}\"", Document.OLD_NAME)},
                                             new[]
                                             {
                                                 new PatchRequest
                                                 {
                                                     Type = PatchCommandType.Modify,
                                                     Name = "Labels",
                                                     AllPositions = true,
                                                     Nested =
                                                         new[]
                                                         {
                                                             new PatchRequest
                                                             {
                                                                 Type = PatchCommandType.Remove,
                                                                 Value = new RavenJValue(Document.OLD_NAME)
                                                             },
                                                             new PatchRequest
                                                             {
                                                                 Type = PatchCommandType.Add,
                                                                 Value = new RavenJValue(Document.NEW_NAME)
                                                             }
                                                         }
                                                 }
                                             }, allowStale: true);
    }
}

When I run I get:

System.InvalidCastException: Unable to cast object of type 'Raven.Json.Linq.RavenJValue' to type 'Raven.Json.Linq.RavenJObject'.
   at Raven.Json.Linq.Extensions.Convert[U](RavenJToken token, Boolean cast) in c:\Builds\RavenDB-Stable\Raven.Abstractions\Json\Linq\Extensions.cs:line 131
   at Raven.Json.Linq.Extensions.Convert[U](RavenJToken token) in c:\Builds\RavenDB-Stable\Raven.Abstractions\Json\Linq\Extensions.cs:line 116
   at Raven.Json.Linq.Extensions.Value[U](RavenJToken value) in c:\Builds\RavenDB-Stable\Raven.Abstractions\Json\Linq\Extensions.cs:line 24
   at Raven.Database.Json.JsonPatcher.ModifyValue(PatchRequest patchCmd, String propName, RavenJToken property) in c:\Builds\RavenDB-Stable\Raven.Database\Json\JsonPatcher.cs:line 138
   at Raven.Database.Json.JsonPatcher.Apply(PatchRequest patchCmd) in c:\Builds\RavenDB-Stable\Raven.Database\Json\JsonPatcher.cs:line 61
   at Raven.Database.Json.JsonPatcher.Apply(PatchRequest[] patch) in c:\Builds\RavenDB-Stable\Raven.Database\Json\JsonPatcher.cs:line 30
   at Raven.Database.DocumentDatabase.<>c__DisplayClassc1.<ApplyPatch>b__be(IStorageActionsAccessor actions) in c:\Builds\RavenDB-Stable\Raven.Database\DocumentDatabase.cs:line 1150
   at Raven.Storage.Esent.TransactionalStorage.Batch(Action`1 action) in c:\Builds\RavenDB-Stable\Raven.Storage.Esent\TransactionalStorage.cs:line 330
   at Raven.Database.DocumentDatabase.ApplyPatch(String docId, Nullable`1 etag, PatchRequest[] patchDoc, TransactionInformation transactionInformation) in c:\Builds\RavenDB-Stable\Raven.Database\DocumentDatabase.cs:line 1131
   at Raven.Database.Impl.DatabaseBulkOperations.<>c__DisplayClass2.<UpdateByIndex>b__1(String docId, TransactionInformation tx) in c:\Builds\RavenDB-Stable\Raven.Database\Impl\DatabaseBulkOperations.cs:line 42
   at Raven.Database.Impl.DatabaseBulkOperations.<>c__DisplayClassa.<PerformBulkOperation>b__5(IStorageActionsAccessor actions) in c:\Builds\RavenDB-Stable\Raven.Database\Impl\DatabaseBulkOperations.cs:line 80
   at Raven.Storage.Esent.TransactionalStorage.ExecuteBatch(Action`1 action) in c:\Builds\RavenDB-Stable\Raven.Storage.Esent\TransactionalStorage.cs:line 376
   at Raven.Storage.Esent.TransactionalStorage.Batch(Action`1 action) in c:\Builds\RavenDB-Stable\Raven.Storage.Esent\TransactionalStorage.cs:line 337
   at Raven.Database.Impl.DatabaseBulkOperations.PerformBulkOperation(String index, IndexQuery indexQuery, Boolean allowStale, Func`3 batchOperation) in c:\Builds\RavenDB-Stable\Raven.Database\Impl\DatabaseBulkOperations.cs:line 75
   at Raven.Database.Impl.DatabaseBulkOperations.UpdateByIndex(String indexName, IndexQuery queryToUpdate, PatchRequest[] patchRequests, Boolean allowStale) in c:\Builds\RavenDB-Stable\Raven.Database\Impl\DatabaseBulkOperations.cs:line 40
   at Raven.Database.Server.Responders.DocumentBatch.<>c__DisplayClass3.<Respond>b__0(String index, IndexQuery query, Boolean allowStale) in c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\DocumentBatch.cs:line 47
   at Raven.Database.Server.Responders.DocumentBatch.OnBulkOperation(IHttpContext context, Func`4 batchOperation) in c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\DocumentBatch.cs:line 64
   at Raven.Database.Server.Responders.DocumentBatch.Respond(IHttpContext context) in c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\DocumentBatch.cs:line 46
   at Raven.Database.Server.HttpServer.DispatchRequest(IHttpContext ctx) in c:\Builds\RavenDB-Stable\Raven.Database\Server\HttpServer.cs:line 550
   at Raven.Database.Server.HttpServer.HandleActualRequest(IHttpContext ctx) in c:\Builds\RavenDB-Stable\Raven.Database\Server\HttpServer.cs:line 316

While I believe the believe the process is correct I must be missing something otherwise it wouldn’t be erroring out.

Please note there is no name on the above nested patches as I have tried a many different combos with the same error. Examples of attempts: “”, “$values”, “Labels”. Same error each time and as a list of strings does not seem to have a Name I left it out in the above on purpose.

Thanks in advance.

  • 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-08T11:58:20+00:00Added an answer on June 8, 2026 at 11:58 am

    I’ve been looking how to do the same thing recently. It sounds like it isn’t possible to use the current patching API to change a string array.

    See the discussion I’ve been having here: https://groups.google.com/forum/#!topic/ravendb/5qYWsq_ny0M

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

Sidebar

Related Questions

With RavenDB, using Fiddler2, I'm trying to make a request to get multiple documents
The question I have is that of securing documents across services using RavenDb and
I'm using RavenDB build 371 and I have the following model: class Product {
I'm using RavenDB to hold several thousand documents. The data comes from a daily
I have integration tests using RavenDB with RunInMemory = true . One of the
We're using RavenDB saga storage, but the saga data isn't being persisted after the
I am new to using RavenDB and trying to get indexes to work in
I'm working on a prototype, using RavenDB, for my company to evaluate. We will
I am using the embedded version of RavenDb and have put the physical database
I am using the clientAPI to query an index (Cards) in RavenDB so: Dim

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.