aws-sdk-js: Dyanmodb.update to delete entry from StringSet does not work
Confirm by changing [ ] to [x] below to ensure that it’s a bug:
- I’ve gone though Developer Guide and API reference
- I’ve checked AWS Forums and StackOverflow for answers
- I’ve searched for previous similar issues and didn’t find any solution
Describe the bug Can not delete a entry from string set using DELETE operation.
Is the issue in the browser/Node.js? Node.js
If on Node.js, are you running this on AWS Lambda?
Details of the browser/Node.js version 10.17.0
SDK version number 2.580.0
To Reproduce (observed behavior) Steps to reproduce the behavior (please share code or minimal repo)
- Create StringSet and put some data in it.
- Delete entry from Set (error)
Invalid UpdateExpression: Incorrect operand type for operator or function; operator: DELETE, operand type: MAP"
problem code.
const dynamoDb = new AWS.DynamoDB.DocumentClient();
const resp = await dynamoDb.scan({
TableName: TABLE_NAME,
FilterExpression: 'attribute_exists(Cids)',
}).promise();
console.info(`Update ${resp.Count} users`);
for (const item of resp.Items || []) {
console.info(item.Uid);
await dynamoDb.update({
TableName: TABLE_NAME,
Key: {
Uid: { S: item.Uid },
},
UpdateExpression: 'DELETE Cids :cameraId',
ReturnValues: 'ALL_NEW',
ExpressionAttributeValues: {
':cameraId': { SS: [id] },
}
}).promise();
}
but same operation in python and CLI works.
Expected behavior Delete the entry from string set.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 17 (3 by maintainers)
DocumentClient.createSet()
works.or
no DocumentClient version works too.
The only workaround possible for me here was not to use a DELETE operation, instead, you gotta query the item, find the index in the array you wish to delete, and remove it a REMOVE operation:
like in this case, arrayField contains an array of Users, and I want to delete by user’s phoneNumber.
const dataStore = await dynamodb.get(queryParams).promise(); let i=0; //save the index for(i = 0; i < dataStore.Item.myTable.length; i++){ if(dataStore.Item.arrayField[i].phone === phoneNumber) { break; } }
//extracted from for loop for clarity
.net dev celerino herrera g https://chamizo.pro/contact
On Fri, Apr 30, 2021 at 1:06 PM Paulo Fagiani @.***> wrote: