Filtering / Querying by the Contents of a List in DynamoDB

后端 未结 2 545
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-02 12:55

I am attempting to filter a DynamoDB query by the contents of a Map contained within a List. Here\'s an example of the structure I\'m dealing with.

{
    \'         


        
相关标签:
2条回答
  • 2021-01-02 13:24

    I found a solution and I tested it, and it is working fine. Here's what I did,

    // 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()
        }))
      }
    });
    

    and then you can query of a nested array of objects:

      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')
      };
    
    0 讨论(0)
  • 2021-01-02 13:29

    This isn't currently supported by DynamoDB's API's expression language (as of November 2014) but there are some workarounds mentioned here.

    0 讨论(0)
提交回复
热议问题