Filtering / Querying by the Contents of a List in DynamoDB

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


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')
  };