ravendbset-basedhttp-patch

Adding an array element to all documents in a collection


My Foo documents have a CustomData collection used to add user-configurable properties.

Sometimes, when I create those properties, I'm need to add them with a default value for indexing purposes.

This is what I'm trying to use for that purpose:

DatabaseCommands.UpdateByIndex(
    "dynamic/Foos",
    new IndexQuery(),
    new[]
    {
        new PatchRequest
        {
            Name = "CustomData",
            Type = PatchCommandType.Add,
            Value = RavenJObject.FromObject(new
                                            {
                                                Value = false,
                                                Bar = new { Baz = "Qux"}
                                            })
        }
    });

This generates the following HTTP request:

PATCH /databases/MyDb/bulk_docs/dynamic/Foos?&pageSize=128&allowStale=False
[
  {
    "Type": "Add",
    "Value": {
      "Value": false,
      "Bar": {
        "Baz": "Qux"
      }
    },
    "Name": "CustomData"
  }
]

And this returns 200 OK, but no documents are modified.


Solution

  • It looks like the problem is the usage of dynamic indexes.

    Switching to a persistent index solved the problem.