ryanfitz/vogels

ValidationException with Indexing stringSet

Opened this issue · 1 comments

Here is my model definition:

var Notification = vogels.define('Notification', {
    tableName: 'notification',
    hashKey: 'notification_id',
    rangeKey: 'createdAt',
    timestamps: true,
    schema: {
        notification_id : vogels.types.uuid(),
        badge: joi.number().integer(),
        delay: joi.number(),
        action: joi.string(),
        body: joi.string(),
        tags: vogels.types.stringSet()
    },
    indexes: [{
        hashKey : 'tags',
        rangeKey: 'createdAt',
        name : 'TagsIndex',
        type : 'global'
    }]
});

However, when I want to create this table, I get the following error:

Error creating tables:  { [ValidationException: Member must satisfy enum value set: [B, N, S]]
  message: 'Member must satisfy enum value set: [B, N, S]',
  code: 'ValidationException',
  time: Thu May 12 2016 14:06:44 GMT-0700 (PDT),
  requestId: 'c775c989-c723-4d55-b319-731230a5991b',
  statusCode: 400,
  retryable: false,
  retryDelay: 0 }

The problem is with the index. I remove that, then it works fine.

Yep, you cannot make an index of Array or Object. StringSet is actually an array. Only [B, N, S] types are allowed to be indexes (binary, number or string).
Here is the documentation of DynamoDB.

When you create a table or a secondary index, you must specify the names and data types 
of each primary key attribute (partition key and sort key). Furthermore, each 
primary key attribute must be defined as type string, number, or binary.

If you want to search by tag you should use scan instead of query.

If you have a gillions of records and the scan is slow for you, there are a few ways to fasten it up:

  • get reserved read capacity,
  • use parallel scan with more than one read capacity. The read capacities are actually not that expensive. About 0.12€ per month (depends on the region).
  • Implement some kind of caching mechanism with inmemorry buffers or use redis for caching.