vogels
vogels copied to clipboard
Update creates another record with new values rather than updating existing record
var InventoryModel = DynamoDb.define(TABLES.INVENTORY, {
hashKey: 'id',
rangeKey: 'name',
timestamps: true,
updatedAt: 'updatedAt',
schema: {
id: DynamoDb.types.uuid(),
name: Joi.string(),
upperName: Joi.string(),
commodity: Joi.string(),
subCommodity: Joi.string(),
uom: Joi.string(), //Unit Of Measurement
isEnable: Joi.boolean() // Delete purpose
},
indexes: [{
hashKey: 'upperName', type: 'global', name: 'UpperNameIndex'
}]
});
While Updating 'rangeKey' attributes value, it creates another record with new values rather than updating existing record.
InventoryModel.update(updateInventory, function (error, response) {
if (!_.isEmpty(error)) {
return callback(error, null);
}
return callback(null, response.attrs);
});
DynamoDB does not support updating an items keys (both hash and range key). The only way to simulate updating primary keys is to create a new entry with the new primary keys and then delete the previous item with the previous primary keys.
We could attempt to add this functionality, but would need to expose an api for passing old / new keys and also get into transaction handling.