![](/img/trans.png)
[英]How to avoid SCAN while filtering on a marketplace app using Dynamodb?
[英]Filtering a nested array with scan in dynamodb
我試圖用嵌套數組計算出 DynamoDB 掃描。 我試圖根據嵌套數組中的調查 ID 獲取用戶詳細信息,我的表值是這樣的。
{
"id": "28009dd8-5802-20f5-c7c9-af53e710ac91",
"user": {
"address1": "1, Park avenue",
"address2": "Austin",
"birthDate": "1999-01-01",
"city": "Austin",
"contact": "9876543210",
"country": "1",
"email": "rajmohan@gm.com",
"emgContact": "2",
"empStatus": "1",
"ethnicity": "5",
"firstName": "Rajmohan",
"gender": "male",
"highLevelEduc": "2",
"image": "",
"lName": "V",
"mName": "",
"nationality": "1",
"relationalStatus": "1",
"state": "43",
"telephone": "9876543210",
"zipCode": "70031"
},
"survey": [
{
"id": "e8de014a-22c1-12bf-4653-577c8031138",
"email": "rajmohan@gm.com",
"method": [
"email"
],
"name": "Rajmohan",
"onDemand": "yes",
"pollSchedule": "None",
"pollTarget": "Educator",
"telephone": "963696369",
"user_id": "413ca05f-ed91-50e7-1974-3e0280ca4a3d"
},
{
"id": "5f4db059-c8a3-e673-iygk-d857425e1077",
"created_at": 1674459043374,
"email": "test@gmail.com",
"method": [
"email"
],
"name": "New testing",
"onDemand": "yes",
"pollSchedule": "None",
"pollTarget": "Educator",
"telephone": "963696369",
"user_id": "413ca05f-ed91-50e7-2635-3e0280ca4a3d"
}
],
"summary": "test",
"user": "413ca05f-ed91-8k8y-2635-3e0280ca4a3d"
}
我的掃描語法就是這樣。
var param = {
TableName: 'user',
FilterExpression: 'contains(#survey.#id,:id)',
ExpressionAttributeNames: {
'#survey': 'survey',
'#id':'id'
},
ExpressionAttributeValues: {
':id': id
},
}
但我無法獲得價值。 我的觀點是基於我需要獲得用戶價值的調查ID。
你不能做你正在嘗試的事情,你需要傳遞 map 的全部價值,我敢肯定這很難做到。
當使用contains
function 時,您需要知道整個 map 值,因為您詢問的是列表中是否包含 map,而不是字符串是否包含在 map 中:
var mymap = {
"id": "e8de014a-22c1-12bf-4653-577c8031138",
"email": "rajmohan@gm.com",
"method": [
"email"
],
"name": "Rajmohan",
"onDemand": "yes",
"pollSchedule": "None",
"pollTarget": "Educator",
"telephone": "963696369",
"user_id": "413ca05f-ed91-50e7-1974-3e0280ca4a3d"
}
var param = {
TableName: 'user',
FilterExpression: 'contains(#survey,:mymap)',
ExpressionAttributeNames: {
'#survey': 'survey'
},
ExpressionAttributeValues: {
':mymap': mymap
},
}
您應該將列表結構化為 map:
"survey": {
"e8de014a-22c1-12bf-4653-577c8031138":{
"email": "rajmohan@gm.com",
"method": [
"email"
],
"name": "Rajmohan",
"onDemand": "yes",
"pollSchedule": "None",
"pollTarget": "Educator",
"telephone": "963696369",
"user_id": "413ca05f-ed91-50e7-1974-3e0280ca4a3d"
},
"5f4db059-c8a3-e673-iygk-d857425e1077": {
"created_at": 1674459043374,
"email": "test@gmail.com",
"method": [
"email"
],
"name": "New testing",
"onDemand": "yes",
"pollSchedule": "None",
"pollTarget": "Educator",
"telephone": "963696369",
"user_id": "413ca05f-ed91-50e7-2635-3e0280ca4a3d"
}
}
var id = "5f4db059-c8a3-e673-iygk-d857425e1077"
var param = {
TableName: 'user',
FilterExpression: 'attribute_exists(#survey.#id)',
ExpressionAttributeNames: {
'#survey': 'survey',
'#id': id
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.