Patching stress

43 views
Skip to first unread message

Paul Eccleston

unread,
Aug 22, 2016, 3:31:01 PM8/22/16
to RavenDB - 2nd generation document database
Hi.  Trying to update an item in a list, but guess I'm doing it wrong :-(

I have this document.

{
    "firstname": "PAUL",
    "phones": [
        {
            "phoneType": "CELL",
            "phoneNumber": "1234"
        },
        {
            "phoneType": "HOME",
            "phoneNumber": "1234"
        }
    ]
}

I want to change the first phone element, phonetype to "BUSINESS" and phone to "999".  Can I do that without patching the two fields individually?

With the code below what actually happens is my array gets messed up.

{
    "firstname": "PAUL",
    "phones": {
        "phoneType": "BUSINESS",
        "phoneNumber": "999"
    }
}

Code snippet below.  Any help would be appreciated.

tp.phones[0].phoneNumber = "999";
tp.phones[0].phoneType = "BUSINESS";

var patchResult = DocumentStore.DatabaseCommands.Patch(
"TEST", new[]
{
new PatchRequest
{
Type = PatchCommandType.Set,
Position = 0,
Name = "phones",
Value = RavenJObject.FromObject(tp.phones[0])
}

});


Paul

Oren Eini (Ayende Rahien)

unread,
Aug 23, 2016, 4:14:52 AM8/23/16
to ravendb
You need to do Insert and Remove.
Set work on objects, not arrays

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


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

Message has been deleted

Paul Eccleston

unread,
Aug 23, 2016, 9:40:56 AM8/23/16
to RavenDB - 2nd generation document database
Thanks Oren, works great.

Paul

Reply all
Reply to author
Forward
0 new messages