如何在Amazon DynamoDB中高效查询嵌套属性?文档结构如下,允许将相关信息存储在文档本身中(而不是引用它)。将研讨会嵌套在课程中存储是有意义的,因为它们很可能会与课程一起查询(它们都是特定于课程的,即课程有许多研讨会,而研讨会属于一个课程)。在我从中迁移的CouchDB中,我可以编写一个视图来查询一些嵌套属性。我了解到我不能投影任何不是顶级属性的东西到dynamodb次要索引中,因此这种方法似乎行不通。这让我回到了问题:如果我不能将它们用作索引中的键,那么如何在没有扫描的情况下高效地查询嵌套属性?例如,如果我想获取Nelson Mandela Theatre的平均出席率,如何查询所有具有“Nelson Mandela Theatre”位置的研讨会中registrations和attendees值,而不必进行扫描?
{
“course_id”: “ABC-1234567”,
“course_name”: “Statistics 101”,
“tutors”: [“Cognito-sub-1”, “Cognito-sub-2”],
“seminars”: [
{
“seminar_id”: “XXXYYY-12345”,
“epoch_time”: “123456789”,
“duration”: “5400”,
“location”: “Nelson Mandela Theatre”,
“name”: “How to lie with statistics”,
“registrations”: “92”,
“attendees”: “61”
},
{
“seminar_id”: “BBBCCC-44444”,
“epoch_time”: “155555555”,
“duration”: “5400”,
“location”: “Nelson Mandela Theatre”,
“name”: “Statistical significance for dog owners”,
“registrations”: “244”,
“attendees”: “240”
},
{
“seminar_id”: “XXXAAA-54321”,
“epoch_time”: “223456789”,
“duration”: “4000”,
“location”: “Starbucks”,
“name”: “Is feral cat population growth a leading indicator for the S&P 500?”,
“registrations”: “40”
}
]
}
{
“course_id”: “CJX-5553389”,
“course_name”: “Cat Health 101”,
“tutors”: [“Cognito-sub-4”, “Cognito-sub-9”],
“seminars”: [
{
“seminar_id”: “TTRHJK-43278”,
“epoch_time”: “123456789”,
“duration”: “5400”,
“location”: “Catwoman Hall”,
“name”: “Emotional support octopi for cats”,
“registrations”: “88”,
“attendees”: “87”
},
{
“seminar_id”: “BBBCCC-44444”,
“epoch_time”: “123666789”,
“duration”: “5400”,
“location”: “Nelson Mandela Theatre”,
“name”: “Statistical significance for cat owners”,
“registrations”: “44”,
“attendees”: “44”
}
]
}