clarkie / dynogels

DynamoDB data mapper for node.js. Originally forked from https://github.com/ryanfitz/vogels
Other
490 stars 110 forks source link

$del operand type #159

Closed mataide closed 6 years ago

mataide commented 6 years ago

This $del operation gives an error:

 Channel.dynamodb().update({
    userId : data['userId'],
    channels  : {$del : data['channel']}
  }, function (err, post) {
    if (err === null) {
      return cb(null, Api.response(post))
    } else {
      console.log(err)
      return cb(null, Api.errors(200, {5: err['message']}))
    }
  })

"Invalid UpdateExpression: Incorrect operand type for operator or function; operator: DELETE, operand type: STRING\"

Object in dynamodb:

{
  "channels": [
    "2d10c266-8319-48cd-9bca-5ee273aaa920"
  ],
  "createdAt": "2018-06-27T16:31:15.020Z",
  "userId": "791908db-3860-4b88-a078-ecb43751a429"
}
cdhowie commented 6 years ago

What is the Channel schema?

mataide commented 6 years ago
_dynogels2.default.define('Channel-' + [constants.PROFILE], {
      hashKey: 'userId',
      timestamps: true,
      tableName: 'Channel-' + [constants.PROFILE],
      schema: _joi2.default.object({
        userId: _joi2.default.string(),
        channels: _joi2.default.array().items(_joi2.default.string()).unique()
      }).unknown(true).options({ stripUnknown: true })
    });
cdhowie commented 6 years ago

DynamoDB does not support $add and $del on arrays, only on sets. You would need to use a string set (dynogels.types.stringSet()) in the schema, for example.