Patch with client API?

279 views
Skip to first unread message

Brian Vallelunga

unread,
Jun 23, 2010, 11:35:16 AM6/23/10
to ravendb
Are there any examples of being able to patch a document using the
client API? I read in another thread that it's possible via the
IDocumentStore object, but can't find any documentation on it.

Thanks

Ayende Rahien

unread,
Jun 23, 2010, 11:42:03 AM6/23/10
to rav...@googlegroups.com
DocumentStore.DatabaseCommands.Batch(
  new PatchCommandData{
        Key = "users/15",
        Patches = new [] {
            Type = "Set",
            Name = "Email",
            Value = "Ayende"
        }
   }
);

Brian Vallelunga

unread,
Aug 2, 2010, 6:39:49 PM8/2/10
to ravendb
Thanks. What about modifying a property of an indexed value in a
document?

Given a document of a class Foo:

public class Foo {
public string Id { get; set; } // Raven key
public Bar[] Children { get; set; }
}

with Bar being:

public class Bar {
public Guid BarId { get; set; } // Never stored as a separate
document
public bool Flag { get; set; }
}

Is it possible to patch a single instance of Bar contained in Foo's
Children array, given Foo's key and Bar's BarId?

Ayende Rahien

unread,
Aug 2, 2010, 7:16:58 PM8/2/10
to rav...@googlegroups.com
No, that isn't possible. You have to know the position of the value to modify it

Brian Vallelunga

unread,
Aug 2, 2010, 10:00:16 PM8/2/10
to ravendb
Correct me if I'm wrong, but there's no concept of child documents/sub
documents, correct? Ideally in my situation, I'd be able to update one
of the child Bar instances directly, even though it's always contained
in a parent document.

The lack of being able to patch a subset of the document contained
within an array might make me redesign this portion of my application.
I might have to break out my Bar instances into individual documents,
even though most of the time I want to access them in distinct sets
under an umbrella of another document.

Ayende Rahien

unread,
Aug 3, 2010, 3:54:00 AM8/3/10
to rav...@googlegroups.com
Brian,
There are considered values, yes.
I wouldn't be too hasty to redesign, though.
There are two other options:
a) create a small plugin for Raven that'll do that for you
b) suggest a syntax for a more complex where for patch

Daniel Steigerwald

unread,
Aug 3, 2010, 5:03:47 AM8/3/10
to ravendb
I would rename Name to Key, since in JSON Name and Index are both
Keys.
obj["Name"] or obj [1], same syntax.

Simple syntax to reach any prop in document:
monsterDocument.children[0].name

For more complex syntax where to patch, a to be convenient with JSON
world, I would chose http://goessner.net/articles/JsonPath/

Ayende Rahien

unread,
Aug 3, 2010, 5:05:06 AM8/3/10
to rav...@googlegroups.com
Oh, we can certainly do that right now, no need to do anything.

Daniel Steigerwald

unread,
Aug 3, 2010, 5:10:40 AM8/3/10
to ravendb
LINQ to JSON?

On 3 srp, 11:05, Ayende Rahien <aye...@ayende.com> wrote:
> Oh, we can certainly do that right now, no need to do anything.
>
> On Tue, Aug 3, 2010 at 12:03 PM, Daniel Steigerwald
> <dan...@steigerwald.cz>wrote:
>
>
>
> > I would rename Name to Key, since in JSON Name and Index are both
> > Keys.
> > obj["Name"] or obj [1], same syntax.
>
> > Simple syntax to reach any prop in document:
> > monsterDocument.children[0].name
>
> > For more complex syntax where to patch, a to be convenient      with JSON
> > world, I would chosehttp://goessner.net/articles/JsonPath/

Ayende Rahien

unread,
Aug 3, 2010, 5:13:03 AM8/3/10
to rav...@googlegroups.com

Daniel Steigerwald

unread,
Aug 3, 2010, 5:59:39 AM8/3/10
to ravendb
I meant LINQ instead of JsonPath in PATCH
curl -X PATCH http://localhost:8080/docs/{document_id} -d
"var a = [{ type: 'patch', linq: 'from doc in docs from foo in
doc.foos ....' value: ''}];

Ayende Rahien

unread,
Aug 3, 2010, 6:03:45 AM8/3/10
to rav...@googlegroups.com
That would require compiling the code, which results in assembly loads, which results in an effective mem leak

John

unread,
Jan 29, 2013, 1:10:30 PM1/29/13
to rav...@googlegroups.com, aye...@ayende.com
So, like this, how can update multiple properties in a Document ?

Matt Warren

unread,
Jan 29, 2013, 1:14:42 PM1/29/13
to ravendb


--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages