Update only a single field of a subobject?


#1

So I noticed here that you can use the doc field in the update API to update single fields. However, I can't seem to get this working when the field is not at the root of the document, without erasing the other fields in the subobject. For example, if I have a document with this structure:

{
    "parent": {
        "child1":1,
        "child2":2,
        "child3":3,
        "child4":4
    }
}

How can I update ONLY child2? If I send {"parent":{"child2":5}}, that will replace the whole parent object. I had thought that maybe I could do {"parent.child2":5}, but that appears to create a new field with the literal name parent.child2. Is what I'm trying to do possible? I know I can retrieve the current value of parent, modify it client-side and resend, but wouldn't there be potential race conditions from that? Thanks.


(Mark Walkom) #2

You need to update the entire structure.

Nested documents may work here, but I am no expert there.


(system) #3