【问题标题】:DynamoDB query for attlibute setDynamoDB 查询属性集
【发布时间】:2019-08-15 18:30:46
【问题描述】:

我对 DynamoDB 比较陌生,目前我正在使用 Node.js 尝试 AWS 示例。我对本教程有疑问:AWS tutorial to load a movie DB and query data.

我想搜索指定演员出演的电影。 例如,“丹尼尔·布鲁尔”和“奥利维亚·王尔德”。 另一个例子,“丹尼尔布鲁尔”或“休杰克曼”。 另外,如果可能的话,我想搜索模糊(例如“??? Bruhl”)。

需要拆分表还是定义过滤器?

样本数据:

{
    "year" : 2013,
    "title" : "Turn It Down, Or Else!",
    "info" : {
        "directors" : [
            "Alice Smith",
            "Bob Jones"
        ],
        "release_date" : "2013-01-18T00:00:00Z",
        "rating" : 6.2,
        "genres" : [
            "Comedy",
            "Drama"
        ],
        "image_url" : "http://ia.media-imdb.com/images/N/O9ERWAU7FS797AJ7LU8HN09AMUP908RLlo5JF90EWR7LJKQ7@@._V1_SX400_.jpg",
        "plot" : "A rock band plays their music at high volumes, annoying the neighbors.",
        "rank" : 11,
        "running_time_secs" : 5215,
        "actors" : [
            "David Matthewman",
            "Ann Thomas",
            "Jonathan G. Neff"
       ]
    }
}

架构:

    TableName : "Movies",
    KeySchema: [       
        { AttributeName: "year", KeyType: "HASH"},  //Partition key
        { AttributeName: "title", KeyType: "RANGE" }  //Sort key
    ],
    AttributeDefinitions: [       
        { AttributeName: "year", AttributeType: "N" },
        { AttributeName: "title", AttributeType: "S" }
    ],
    ProvisionedThroughput: {       
        ReadCapacityUnits: 10, 
        WriteCapacityUnits: 10
    }

表格填满:

allMovies.forEach(function(movie) {
    var params = {
        TableName: "Movies",
        Item: {
            "year":  movie.year,
            "title": movie.title,
            "info":  movie.info
        }
    };

   docClient.put(params, function(err, data) {
       if (err) {
           console.error("Unable to add movie", movie.title, ". Error JSON:", JSON.stringify(err, null, 2));
       } else {
           console.log("PutItem succeeded:", movie.title);
       }
    });

【问题讨论】:

    标签: amazon-dynamodb


    【解决方案1】:

    查看Specifying Item Attributes 文档。您的info 字段是 JSON,因此可以告诉 Dynamo 查看子字段、子子字段等。

    然后,将这些与Condition Expressions 结合起来以获得您想要的功能。

    请记住,尽管这些事情是可能的,但它们是否有效仍取决于表架构。 Looking around a bit 我不认为您可以在 actors 子字段上建立索引,因此如果您希望此类查询更快,则需要将该数据提取到其自己的列中以便在其上建立索引。

    【讨论】:

      猜你喜欢
      • 2021-12-27
      • 2022-01-10
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 2022-08-11
      相关资源
      最近更新 更多