user9445
user9445

Reputation: 465

Lambda + Nodejs + dynamodb : storing json : Why put item storing data types?

I'm trying to store the json object in dynamodb using the code given below.

exports.handler = function (event, context, callback) {

    var docClient = new AWS.DynamoDB.DocumentClient();

    var table = "Logs";

    id_val = 1
    var params = {
        TableName: table,
        Item: {
            "id": id_val,
            "message": event
        }
    };

    docClient.put(params, function(err, data) {
        if (err) {
            callback(null, JSON.stringify(err, null, 2));
            context.fail("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));
        }
    });
}

Input to event

[
    {
        "id": 1,
        "demographic": {
            "firstName": "John",
            "middleName": "w",
            "lastName": "Doe",
            "suffix": "jr",
            "birthDate": "1990-02-02",
            "gender": "M",
            "ssn": 123
        }
    }
]

What's stored in the table

{
    "id": {
        "N": "84.20420287568176"
    },
    "message": {
        "L": [
            {
                "M": {
                    "demographic": {
                        "M": {
                            "birthDate": {
                                "S": "1990-02-02"    
       ...
       ...
       ...

Why is datatype being stored in the table? How can one break this down so that attributes are stored separately?

Upvotes: 1

Views: 2708

Answers (1)

Vijayanath Viswanathan
Vijayanath Viswanathan

Reputation: 8541

That's the way dynamoDB stores data because when we look at the data we should be able to know the datatype of the field, which is excatly same as data type of column in relationa data base. Though data stores and displays like this in dynamoDB when we get data from dynamoDB through an actual application or API we can get rid of data types, which will return the actual data only.

Upvotes: 1

Related Questions