使用Node Js在Dynamo数据库中更新集合 [英] Updating a Set in Dynamo db using Node Js

查看:124
本文介绍了使用Node Js在Dynamo数据库中更新集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行发电机db列表中最简单的操作之一更新。

I am trying to do one of the most simple operations "Update" in a dynamo db list.

表模式-

businessId : String, customers: StringSet,  itemCode : NumberSet

我有一个通过put插入的条目-

I have an entry inserted via put -

bussinessId = "sampleBusiness", cuatomers 0: "cust1", itemCode 0: 4554

我想使用update添加更多项,这是我尝试过的操作-

I want to add more items using update and here is what I have tried -

 var updateRequest = {  
    'TableName' : tableName,
    'Key' : {
        'businessId' : {
            "S" : businessId
        }
    },
    'UpdateExpression' : "SET itemCode[2] =:attrValue",    
    'ExpressionAttributeValues' : {
        ':attrValue' : {
            "N" : "564564"
        }
    }
};

这给了我错误-


文档中提供的文档路径无效

Document Path provided in document is invalid

我想附加新条目,因此也尝试了此操作-

I wanted to append new entries so tried this as well -

var sm = [];
sm[0] = "56465";

//Add business to 
var updateRequest = {  
    'TableName' : tableName,
    'Key' : {
        'businessId' : {
            "S" : businessId
        }
    },
    'UpdateExpression' : 'SET #attrName = list_append(#attrName, :attrValue)',
    'ExpressionAttributeNames' : {
        '#attrName' : 'itemCode'
    },
    'ExpressionAttributeValues' : {
        ':attrValue' : {
            "NS" : sm
        }
    }
  };

这给出:


ValidationException:无效的UpdateExpression:运算符或函数的操作数类型错误;运算符或函数:list_append,操作数类型:NS

ValidationException: Invalid UpdateExpression: Incorrect operand type for operator or function; operator or function: list_append, operand type: NS

也尝试过此操作-

 ':attrValue' : {
                "N" : "4564"
            }

但同样的错误。

根据 http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Modifying.html ,它将为 FiveStar 评论列表添加一个新元素。表达式属性名称 #pr ProductReviews ;属性值:r 是一个单元素列表。如果列表以前有两个元素[0]和[1],则新元素将为[2]。

As per the example provided in http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Modifying.html , it adds a new element to the FiveStar review list. The expression attribute name #pr is ProductReviews; the attribute value :r is a one-element list. If the list previously had two elements, [0] and [1], then the new element will be [2].

SET #pr.FiveStar = list_append(#pr.FiveStar, :r) 

这表示:r 是一个元素列表

我在这里丢失了一些东西。要求是否有人可以提供帮助。打击了很长时间。我只想使用nodeJS在dynamo数据库中添加元素。

I am missing some thing here. Request if any one can help. Struck on this for long time. I just want to append elements in set in dynamo db using nodeJS.

推荐答案

它看起来像这样:

'ExpressionAttributeValues' : {
    ':attrValue' : {
        "NS" : sm
    }
}

应该是这样:

'ExpressionAttributeValues' : {
    ':attrValue' : {
        "S" : sm
    }
}

或者您需要将此值强制转换为 sm [0] = 56465; 更改为数字 Number( 56465)并更改:attrValue 数据类型 S N

Or you need to cast this value sm[0] = "56465"; to a Number Number("56465") and change the :attrValue data type "S" to "N". Depends on how you have your table configured.

也有可能应该将:attrValue 分配为 S:sm [0] ,因为现在您正在传递 S 整个数组。

It's possible too that you should assign :attrValue to be "S" : sm[0] because right now you are passing an "S" a whole array.

这篇关于使用Node Js在Dynamo数据库中更新集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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