在dynamoose上更新ValidationException:键上的条件数无效

时间:2019-02-25 08:47:25

标签: amazon-dynamodb dynamoose

下午好

动态模式更新会引发ValidationException错误:键上的条件数无效。我尝试过调试,这是导出DEBUG = dynamoose *

的调试结果
dynamoose:model Update {"key":"1","email":"biraj@gmail.com"} +24s
  dynamoose:attribute toDynamo {"S":"1"} +24s
  dynamoose:attribute toDynamo {"N":"1550997177674"} +2ms
  dynamoose:attribute toDynamo {"N":"1550997177674"} +2ms
  dynamoose:table Waiting for Active table, Chat, {"update":true,"create":true,"waitForActive":true,"waitForActiveTimeout":180000,"prefix":"","suffix":""} +24s
  dynamoose:table Waiting... +4ms
  dynamoose:table index idGlobalIndex.IndexStatus is ACTIVE +22ms
  dynamoose:model updateItem { TableName: 'Chat',
  Key: { key: { S: '1' }, initiate_time: null },
  ExpressionAttributeNames: { '#_n0': 'update_time' },
  ExpressionAttributeValues: { ':_p0': { N: '1550997177674' } },
  ReturnValues: 'ALL_NEW',
  UpdateExpression: 'SET #_n0 = :_p0 ' } +34ms 

这是执行时返回的错误:

dynamoose:model Error returned by updateItem { ValidationException: The number of conditions on the keys is invalid
    at Request.extractError (/home/vagrant/api/node_modules/aws-sdk/lib/protocol/json.js:51:27)
    at Request.callListeners (/home/vagrant/api/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/home/vagrant/api/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/home/vagrant/api/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/home/vagrant/api/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/vagrant/api/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/vagrant/api/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/vagrant/api/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/vagrant/api/node_modules/aws-sdk/lib/request.js:685:12)
    at Request.callListeners (/home/vagrant/api/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
    at Request.emit (/home/vagrant/api/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/home/vagrant/api/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/home/vagrant/api/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/vagrant/api/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/vagrant/api/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/vagrant/api/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/vagrant/api/node_modules/aws-sdk/lib/request.js:685:12)
    at Request.callListeners (/home/vagrant/api/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
    at callNextListener (/home/vagrant/api/node_modules/aws-sdk/lib/sequential_executor.js:96:12)
    at IncomingMessage.onEnd (/home/vagrant/api/node_modules/aws-sdk/lib/event_listeners.js:299:13)
    at IncomingMessage.emit (events.js:193:15)
    at IncomingMessage.EventEmitter.emit (domain.js:441:20)
    at endReadableNT (_stream_readable.js:1129:12)
    at process.internalTickCallback (internal/process/next_tick.js:72:19)
  message: 'The number of conditions on the keys is invalid',
  code: 'ValidationException',
  time: 2019-02-25T08:32:57.732Z,
  requestId: '0bc7c973-6912-40f1-a270-ecbc13551e20',
  statusCode: 400,
  retryable: false,
  retryDelay: 5.042568165458738 } +26ms
{ ValidationException: The number of conditions on the keys is invalid
    at Request.extractError (/home/vagrant/api/node_modules/aws-sdk/lib/protocol/json.js:51:27)
    at Request.callListeners (/home/vagrant/api/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/home/vagrant/api/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/home/vagrant/api/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/home/vagrant/api/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/vagrant/api/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/vagrant/api/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/vagrant/api/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/vagrant/api/node_modules/aws-sdk/lib/request.js:685:12)
    at Request.callListeners (/home/vagrant/api/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
    at Request.emit (/home/vagrant/api/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/home/vagrant/api/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/home/vagrant/api/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/vagrant/api/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/vagrant/api/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/vagrant/api/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/vagrant/api/node_modules/aws-sdk/lib/request.js:685:12)
    at Request.callListeners (/home/vagrant/api/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
    at callNextListener (/home/vagrant/api/node_modules/aws-sdk/lib/sequential_executor.js:96:12)
    at IncomingMessage.onEnd (/home/vagrant/api/node_modules/aws-sdk/lib/event_listeners.js:299:13)
    at IncomingMessage.emit (events.js:193:15)
    at IncomingMessage.EventEmitter.emit (domain.js:441:20)
    at endReadableNT (_stream_readable.js:1129:12)
    at process.internalTickCallback (internal/process/next_tick.js:72:19)
  message: 'The number of conditions on the keys is invalid',
  code: 'ValidationException',
  time: 2019-02-25T08:32:57.732Z,
  requestId: '0bc7c973-6912-40f1-a270-ecbc13551e20',
  statusCode: 400,
  retryable: false,
  retryDelay: 5.042568165458738 }

以下是正在执行操作的聊天模式:

var dynamoose = require('dynamoose');

var ChatSchema = new dynamoose.Schema({
  id:{
    type: String,
    index: {
      global:true
    }
  },
  key: {
    type: String,
    hashKey: true,
    default:"1"
  },
  category_id: {
    type: String
  },
  initiate_time: {
    type: Date,
    rangeKey: true
  },
  update_time: {
    type: Date,
    index: {
      global: false,
      name:"UpdateTimeSecondaryIndex"
    }
  },
  name: {
    type: String
  },
  email: {
    type: String,
    index: {
      global: false
    }
  },
  support_id: {
    type: String
  }

});

ChatSchema.method('getLanguages', async function () {
    var {ChatLang} = require("./index");
    var languages = await ChatLang.query({chatId: this.id}).exec();
    if (languages != null && languages.length > 0)
    {
      return languages;
    }
    return false;
});


module.exports = ChatSchema;

这是实际的更新代码:

try {
      await Chat.update({
        key: "1",
        email: args.chat.email
      }, {
          update_time: Moment().subtract(24, "hours"),
          initiate_time: Moment().subtract(24, "hours")
        });
    } catch (err) {
      console.log(err);
    }

感谢您提供任何线索和帮助。

0 个答案:

没有答案