2

I insert an array of string to DynamoDB:

[13, 12, 12, 4]

It becomes Array of Objects when I view it in DynamoDB:

[ { "S" : "13" }, { "S" : "12" }, { "S" : "12" }, { "S" : "4" }]

Is it reasonable? Do I need to do something to make my data being inserted as array of string?

Here is how I put my array to DynamoDB:

var params = {
   TableName: "MatchDate",
   Item:{
      position: [1, 3, 4, 5]
   }
};

DynamoDBClient.put(params, function(err, data) {
   //Some other code
});

1 Answer 1

6

If you want a single object (an array of strings) you need to set your attribute type to String Set

Then you will get

"SS": ["13", "12" ,"12", "4"]

Or you can use Number Set

"NS": ["13", "12" ,"12", "4"]

EDIT: Try something like this in nodejs

var params = {
   TableName: "MatchDate",
   Item: {
   "position": {
      SS: [
         '12',
         '13',
         '4'
      ]
   }
};

DynamoDBClient.put(params, function(err, data) {
   //Some other code
});

Check here for AWS Refernce of Javascript putItem

Sign up to request clarification or add additional context in comments.

3 Comments

Where should I set this?
If you post your existing putItem command I can give you a better answer. For now I have updated the answer with a generic example. I think your're using php right?
I have edited my post and included the command i written in nodejs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.