how to define attribute types in Dynamodb?

813 Views Asked by At

I want to store data attributes are threadId , threadType (sms, livechat ,fb) , createat and updateat how I define the threadType I follow this procedure but output displays all of the types of threadType?

and how to fix the time? this is manual input is there any method to get system time?

var doClient = new AWS.DynamoDB.DocumentClient();
  var DynamoDB = new AWS.DynamoDB({});

  var table = "thread";

  var threadId = "3";
  var threadType = "livechat";
  var createDate = "11:38";
  var updateDate = "12:00";
  var channelName = "three";

  var params = {
      TableName : table,
      Item: 
      {
        "threadId" : threadId,
        "threadType" : { "SS": ["sms", "livechat" ,"fb"] },
        "createDate" : { 'S' : createDate },
        "updateDate" : { 'S' : updateDate },
        "channelName" :{'S' : channelName }
      }      
  };


  console.log("Adding a new item...");
  doClient.put(params, function(err, data) {
      if (err) {
          console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));
      } else {
          console.log("Added item:", JSON.stringify(data, null, 2));
      }
  });

I need that only livechat display in a result of threadtype because in this insertion I need livechat

1

There are 1 best solutions below

0
On

It looks like you are modelling threadType as a StringSet, which means that it can contain multiple values. If you just want to store 'livechat' then just store this value as a String. DynamoDB doesn't have the concept of server side validation, or support for Enums, though some SDK's do - in node.js there is no Enum type. As for the system time, there is no way to ask for DynamoDB to insert the system time for you. Most people will insert epoch seconds or milliseconds as a Number type for sorting purposes, and based on the client's timestamp, which should use NTP and when hosted within EC2 will be super super close to the DDB fleet timestamp.