Updating a existing Dynamodb Item to change single attribute of it with just partition and sort key inputs in query

0

Hi All,

is it possible to update a single attributes of a Dynamodb Item with out overriding the existing details of other attributes ??

Example : attributes in a dynamo item -> Employee_Id(partition key), Employee_Department(sort key), Employee_Address, Employee_experience

and want to update only employee_experience with only providing Employee_Department (sort key) in query

Currently I am using the following query to update the Employee_experience however Employedd_address is getting overriden to empty after executing this query

Query ::

QueryEnhancedRequest.builder() .queryConditional(QueryConditional.keyEqualTo(Key.builder().partitionValue(Employee_Department).build())) .exclusiveStartKey(startKey) .scanIndexForward(false) .build();

Please kindly let me know if you need any further details

Sathwik
질문됨 7달 전568회 조회
1개 답변
1
수락된 답변

You cannot update values of an item using a read api such as Query. You must use UpdateItem:

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

profile pictureAWS
전문가
답변함 7달 전
profile picture
전문가
검토됨 2달 전
  • Hi @Leeroy Hannigan, Thanks for the suggestion I changed the logic to update a item in dynamoDB which helped me to solve the problem Initially I used : employeeTable.updateItem(Employeeitem) Note : *EmployeeItem = the modelled item to be inserted into or updated in the database table.

    Updated logic: I updated the logic to use updateItem(UpdateItemEnhancedRequest<T> request) with UpdateQuery

    UpdateItemEnhancedRequest<Employee> request = UpdateItemEnhancedRequest .builder(Employee.class) .item(employee) .ignoreNulls(true) -> this actually helped me avoid overriding the existing data with null values in update query .build();

    Thanks for you help and pointing to me correct documentation

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

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

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

관련 콘텐츠