How can i update an object

0

Hello, i got a problem

I use DynamoDB with Serverless.
I have a request that allows me to update an item from my table. But one of the objects of this item is like this :

"example1":{
"example2":{
"name1" : "blabla"
}
}
I want to add values in example2, like "name2", "name3" ...
My request with UpdateExpression and ExpressionAttributeValues looks like this :

let params = {
...
UpdateExpression: "SET example1.example2.name2 = :name2, example1.example2.name3 = :name3",
ExpressionAttributeValues: {
":name2": name2,
":name3" : name3
},
...
ReturnValues: 'UPDATED_NEW'
}
And when i run my request i got an answer like this "message":"The document path provided in the update expression is invalid for update"

Can you help me if you already have something like this ?

Thanks

Best regards

dc-two
gefragt vor 5 Jahren2311 Aufrufe
3 Antworten
0

Hi, I am reviewing this now, and will send you an update once I have more information. Thank you.

AWS
beantwortet vor 5 Jahren
0

I tried the following:

#Existing item json:

c:\PADMA\UTILS\SCRIPTS>aws dynamodb scan --table-name example
{
    "Items": [
        {
            "pk": {
                "N": "1"
            },
            "example1": {
                "M": {
                    "example2": {
                        "M": {
                            "name2": {
                                "S": "a"
                            },
                            "name1": {
                                "S": "blabla"
                            }
                        }
                    }
                }
            },
            "sk": {
                "S": "key"
            }
        }
    ],
    "Count": 1,
    "ScannedCount": 1,
    "ConsumedCapacity": null
}

#Update command:

table.update_item(
    Key={
        'pk': pk,
        'sk': sk
    },
    UpdateExpression="set example1.example2.name3=:x",
    ExpressionAttributeValues={
        ':x': "new value"
    },
    ReturnValues="UPDATED_NEW"
)

#Updated item json:

c:\PADMA\UTILS\SCRIPTS>aws dynamodb scan --table-name example
{
    "Items": [
        {
            "pk": {
                "N": "1"
            },
            "example1": {
                "M": {
                    "example2": {
                        "M": {
                            "name1": {
                                "S": "blabla"
                            },
                            "name2": {
                                "S": "a"
                            },
                            "name3": {
                                "S": "new value"
                            }
                        }
                    }
                }
            },
            "sk": {
                "S": "key"
            }
        }
    ],
    "Count": 1,
    "ScannedCount": 1,
    "ConsumedCapacity": null
}

Is this what you are trying to do? I am getting the expected results. I followed this tutorial: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.Python.01.html
Can you try this out. And let me know if you are still having trouble with this?

AWS
beantwortet vor 5 Jahren
0

Yes, that's work

My mistake was that one of my values ​​had to be created in a new object, but since the object did not exist, it did not understand the path.

Thanks for your help

dc-two
beantwortet vor 5 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen