【问题标题】:Filtering / Querying by the Contents of a List in DynamoDB按 DynamoDB 中列表的内容过滤/查询
【发布时间】:2014-11-17 19:12:28
【问题描述】:

我正在尝试通过列表中包含的地图内容过滤 DynamoDB 查询。这是我正在处理的结构示例。

{
    'EventType': 'git/push'
    'EventTime': 1416251010,
    'Commits': [
        {
            'id': '29d02aff...',
            'subject': 'Add the thing to the place'
        },
        {
            'id': '9d888fec...',
            'subject': 'Spelling errors'
        },
        ...
    ]
}

哈希键是EventType 和范围键EventTime。我正在尝试编写一个过滤器,将查询结果过滤到特定的id。是否可以创建一个 DynamoDB 过滤器表达式来正确过滤这样的查询? (我的第一个想法是使用contains (a, a),但我认为这不适用于地图列表。)

【问题讨论】:

    标签: amazon-dynamodb nested-queries nosql


    【解决方案1】:

    DynamoDB 的 API 表达式语言目前不支持此功能(截至 2014 年 11 月),但提到了一些解决方法here

    【讨论】:

    • 我们绕了一圈;我是在 AWS 论坛上提出这个问题的人。
    【解决方案2】:

    我找到了一个解决方案并对其进行了测试,它运行良好。 这就是我所做的,

    // created a schema like that:
    
    var Movie = dynamo.define('example-nested-attribute', {
      hashKey : 'title',
      timestamps : true,
      schema : {
        title       : Joi.string(),
        releaseYear : Joi.number(),
        tags        : dynamo.types.stringSet(),
        director    : Joi.object().keys({
          firstName : Joi.string(),
          lastName  : Joi.string(),
          titles    : Joi.array()
        }),
        actors : Joi.array().items(Joi.object().keys({
          firstName : Joi.string(),
          lastName  : Joi.string(),
          titles    : Joi.array()
        }))
      }
    });
    

    然后您可以查询嵌套的对象数组:

      var params = {};
      params.UpdateExpression = 'SET #year = #year + :inc, #dir.titles = list_append(#dir.titles, :title), #act[0].firstName = :firstName ADD tags :tag';
      params.ConditionExpression = '#year = :current';
      params.ExpressionAttributeNames = {
        '#year' : 'releaseYear',
        '#dir' : 'director',
        '#act' : 'actors'
      };
      params.ExpressionAttributeValues = {
        ':inc' : 1,
        ':current' : 2001,
        ':title' : ['The Man'],
        ':firstName' : 'Rob',
        ':tag' : dynamo.Set(['Sports', 'Horror'], 'S')
      };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-30
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      • 2021-08-02
      相关资源
      最近更新 更多