属性不能包含空字符串 [英] Attribute may not contain an empty string

查看:572
本文介绍了属性不能包含空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解析CSV文件并将数据放入具有AWS DynamoDB的表中。

parsing a CSV file and putting the data in a table with AWS DynamoDB.

因为它现在,我得到以下错误:

As it stands right now, I am getting the following error:

或更多的参数值无效:AttributeValue不能包含空字符串

...在将数据放入表中之前。

... BEFORE it puts the data in the table. The data is getting to the table, but not before spamming me with that error a million times.

我的代码:

var csv = require("fast-csv");

csv.fromPath(file, {
        headers: true,
        ignoreEmpty: true
    })
    .on("data", function(data) {

        for (var key in data) {
            if (data.hasOwnProperty(key)) {
                if (data[key] === "" || data[key] === undefined || data[key] === null) {
                    data[key] = "N/A";
                }
            }

            params = {
                TableName: tableName,
                Item: {
                    RefID: {
                        S: data["Ref-ID"]
                    },
                    //lots of other data
                }
            };
            dynamodb.putItem(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));
                }
            });
        }

    })
    .on("end", function() {
        console.log("done");
    });

如你所见,我将任何可能的空字符串转换为== N / A ,以尝试解决此问题。有任何想法吗?

As you can see, I am converting any possible empty strings to == N/A in an attempt to solve this problem. Any thoughts?

编辑:

原来是 undefined 当它应该显示它在表中放置什么。

This turns out to be undefined when it should display what it put in the table.

console.log("Added item:", JSON.stringify(data[key], null, 2));

EDIT 2:已更改此代码...

EDIT 2: Changed this code...

dynamodb.putItem(params, function(err, data)

... to this:

...to this:

dynamodb.putItem(params, function(err, info)

我仍然得到错误,但现在正确显示表。

I am still getting the errors, but am now displaying the table correctly.

推荐答案

看来dynamoDB在这个时候不允许空字符串。我不明白为什么,但是从这个日期,你不能不存储一个属性键: 。

It appears that dynamoDB at this time does not allow empty strings. I can NOT understand why, but as of this date you cannot not store an attribute of "Key":"".

请投诉亚马逊。key =和key = null是非常不同的用例,需要。

Please complain to amazon about it. key="" and key=null are very different use cases and are needed.

这篇关于属性不能包含空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆