[英]PynamoDB Error for Local Secondary Index: ValueError('Table table_4 has no index: key1_index',)
[英]Secondary Index not working for Database using @key
我應該為 Justin 獲取 DynamoDb id。 調用似乎沒有失敗。 如果我console.log(returned)
我得到一個[object Object]
。 當我嘗試訪問returned.data.getIdFromUserName.id
或returned.data.getIdFromUserName.email
(表中的任何其他內容)時,我得到undefined
。 我錯過了什么?
返回數據:
{
"data": {
"getIdFromUserName": {
"items": [
{
"id": "3a5a2ks4-f137-41e2-a604-594e0c52a298",
"userName": "Justin",
"firstname": "null",
"weblink": "@JustinTimberlake",
"email": "iuiubiwewe@hotmail.com",
"mobileNum": "+0123456789",
"profilePicURI": "null",
"listOfVideosSeen": null,
"userDescription": "I wanna rock your body, please stay",
"isBlocked": false,
"GridPairs": null
}
],
"nextToken": null
}
}
}
我建議更好地了解console.log(returned)
正在打印什么。
嘗試console.log(JSON.stringify(returned, null, 2))
檢查返回的內容。
編輯:您正在使用的數據如下所示:
{
"data": {
"getIdFromUserName": {
"items": [
{
"id": "3a5a2ks4-f137-41e2-a604-594e0c52a298",
"userName": "Justin",
"firstname": "null",
"weblink": "@JustinTimberlake",
"email": "iuiubiwewe@hotmail.com",
"mobileNum": "+0123456789",
"profilePicURI": "null",
"listOfVideosSeen": null,
"userDescription": "I wanna rock your body, please stay",
"isBlocked": false,
"GridPairs": null
}
],
"nextToken": null
}
}
}
密切注意該響應的結構。 data
和getIdFromUserName
都是地圖。 data.getIdFromUserName
的內容是一個名為items
的數組。 因此, data.getIdFromUserName.items
是一個包含查詢結果的數組。 您需要遍歷該數組以獲取您要查找的數據。
例如, data.getIdFromUserName.items[0].id
將是3a5a2ks4-f137-41e2-a604-594e0c52a298
要訪問 email,它將是data.getIdFromUserName.items[0].email
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.