admin管理员组文章数量:1315999
I'm using put and get without problems, but when it es to delete, nothing happens. Here's my code:
async function resetUserIdDB(userId) {
let params = {
TableName: 'TableName',
"Key": {
"userId": {
"S": userId.toString()
}
}
};
try {
const dbResponse = await ddb.deleteItem(params).promise();
console.log(`dbresponse has params of ${JSON.stringify(params)} and response of ${JSON.stringify(dbResponse)}`);
if (dbResponse.Item) {
console.log(`deleted row with userId of ${userId}`);
return (dbResponse);
}
} catch (err) {
console.log(`user reset failed with ${err}`);
throw new Error(`failed to reset because of ${err}`);
}
}
The params all look fine, but I just get an empty response, and no error, but no deletion either. I'm using the same .promise() on all my other dynamodb actions.
Any ideas?
I'm using put and get without problems, but when it es to delete, nothing happens. Here's my code:
async function resetUserIdDB(userId) {
let params = {
TableName: 'TableName',
"Key": {
"userId": {
"S": userId.toString()
}
}
};
try {
const dbResponse = await ddb.deleteItem(params).promise();
console.log(`dbresponse has params of ${JSON.stringify(params)} and response of ${JSON.stringify(dbResponse)}`);
if (dbResponse.Item) {
console.log(`deleted row with userId of ${userId}`);
return (dbResponse);
}
} catch (err) {
console.log(`user reset failed with ${err}`);
throw new Error(`failed to reset because of ${err}`);
}
}
The params all look fine, but I just get an empty response, and no error, but no deletion either. I'm using the same .promise() on all my other dynamodb actions.
Any ideas?
Share Improve this question asked Sep 7, 2018 at 17:17 digitaltoastdigitaltoast 6898 silver badges24 bronze badges 3- Maybe the item with that Key is not found. – Faizuddin Mohammed Commented Sep 7, 2018 at 17:52
- Good thinking, but that's why I logged out the params, just to check. The UserId matches fully, for case and type. And if I make a "wrong" param, like UserID, then I get an expected error, like "The provided key element does not match the schema". – digitaltoast Commented Sep 7, 2018 at 19:38
- can you show the ddb var, dynamodb AWS initialisation ! – Sid Ali Commented Sep 8, 2018 at 15:01
3 Answers
Reset to default 4I just ran into the same problem. It seems like some of the SDK functions don't actually work unless you pass them a callback
parameter, even though it's optional. Even a function that does nothing seems to make it work. i.e.
const dbResponse = await ddb.deleteItem(params, () => {}).promise();
When you delete an element in Dynamodb and nothing happen, it means that the key wasn't found, so double check your key.
The table exist, otherwise you would have had an error saying
.amazonaws.services.dynamodb.model.ResourceNotFoundException: Requested resource not found (Service: AmazonDynamoDB; Status Code: 400; Error Code: ResourceNotFoundException; Request ID
For example to delete in the table :
TABLEXAMPLE the key : {id: "client", sortingKey: "TTN-BPLAN-7129-6114"}
check that the id exists and is correct, also the sorting key exists and is correct
Not sure, but the following might help to debug in general:
- try to remove async/await while testing.
- remove 'promise()' after call to 'deleteItem' (try to test one thing at a time).
- do not throw from the catch block, but return err.
- the "Key" object is in quotes. It may not have to be in quotes just like TableName.
basically, make the code simpler. It will help to debug.
本文标签: javascriptDynamoDB DeleteItem apparently not workingno error givenStack Overflow
版权声明:本文标题:javascript - DynamoDB DeleteItem apparently not working - no error given - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741994262a2409721.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论