0

good afternoon

dynamoose modal update throwing an error of ValidationException: The number of conditions on the keys is invalid. i am tried debbuging here is the debug result from export 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 

and here is the returned error with the execution :

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 }

here is the chat modalin which the operation is being done:

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;

and here is the actual code for update:

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

any clues and help is appreciated thank you.

ydvsailendar
  • 15
  • 10
  • `email` isn’t part of the key. So you shouldn’t have that in your first object in your update call. Can you try removing that? – Charlie Fish Feb 25 '19 at 21:03
  • @CharlieFish having `email: { global: false}` which means it's a global secondary index...shouldn't that suffice in having a query using the hashKey (*key*) and the secondary index (*email*)? – Dean Feb 26 '19 at 03:22
  • @Dean That isn’t what his code has. And that was part of an index. So no. – Charlie Fish Feb 26 '19 at 03:34
  • @CharlieFish his code has this `{ key: { type: String, hashKey: true, default:"1" }, email: { type: String, index: { global: false } },` so my understanding is that `email` is sorta like a secondary rangeKey to the hashKey `key`. So his query is querying against the hashKey and the rangeKey (secondary index)..what am I missing here? – Dean Feb 26 '19 at 03:58
  • @Dean Not when it’s an index. Index is separate from the main key stuff. – Charlie Fish Feb 26 '19 at 04:22
  • @CharlieFish sorry I dont think I get what you're saying. Let me know if I'm wrong. Essentially if there's a `hashkey: key` and `rangeKey: initiate_time` and I specify a local secondary index `email: {global: false}`.....I assume the *email* is another sort key to the *initiate_time*...I thought I can query using *hashKey and the local secondary index* and exclude the main `rangeKey` – Dean Feb 26 '19 at 04:30
  • @Dean This case is very specific. On our GitHub page there is a Slack invite link. Message me there and I can explain better. https://github.com/dynamoosejs/dynamoose – Charlie Fish Feb 26 '19 at 04:32

0 Answers0