How to update records in dynamo db?

0

I have updated an item in dynamodb (code sample below), so far i have updated item with attributes that already exist . if we have to add a new attribute to an exiting record, how to do it ?

also , is there a way we can update items in batch?

import boto3
db = boto3.resource("dynamodb")
table = db.Table("mytable")
def update_item():
    response = table.update_item(
        Key={"email": "abc@example.com"},
        UpdateExpression="set #name = :n",
        ExpressionAttributeNames={
            "#name": "name",
        },
        ExpressionAttributeValues={
            ":n": "John Doe",
        },
        ...
    )
已提问 4 个月前329 查看次数
1 回答
2

Schemaless

One of DynamoDB's distinctive features is its schemaless nature, which means that unlike traditional relational databases, DynamoDB doesn't require a predefined schema for data tables. This allows developers to add or remove fields on the fly without the need for a rigid structure.

In DynamoDB, each item in a table is uniquely identified by a primary key. When making requests, especially for read and write operations, it's crucial to include the primary key attributes in order to interact with the database effectively. Any attributes which are not related to the keys can be included or not, on a per item basis.

Batch Updates

DynamoDB does not provide the ability to Batch Update, not natively. You can BatchWrite, but that overwrites data, its not an upsert. The PartiQL API allows you to use BatchExecuteStatement and can act as a work-around to allow you to do Batch Updates of items up to 25 per batch.

https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchExecuteStatement.html

profile pictureAWS
专家
已回答 4 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容