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달 전326회 조회
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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠