如何在dynamoDB中返回插入的项目 [英] How to return the inserted item in dynamoDB

查看:24
本文介绍了如何在dynamoDB中返回插入的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 nodeJS sdk 将项目放入 dynamoDB,项目是:

I am using nodeJS sdk to put the item to dynamoDB, The item is:

{
   "eventId": date + '-' + eventName + '-' + eventPurpose,
   "eventName": eventName,
   "eventPurpose": eventPurpose,
   "eventDates": eventDates,
   "attendees": attendees
 }

将项目放入 dynamoDB 的当前代码:

The present code for the putting the item in dynamoDB:

  const params = {
    TableName: "event",
    Item: {
        "eventId": date + '-' + eventName + '-' + eventPurpose,
        "eventName": eventName,
        "eventPurpose": eventPurpose,
        "eventDates": eventDates,
        "attendees": attendees
    },
    ReturnValues: "ALL_OLD"
  };

  dynamo.put(params, (err, data) => {
    console.log("coming here");
    if (err) {
      console.log("error : " + JSON.stringify(err));
    }
    console.log("data" + JSON.stringify(data));
    cb(null, data);
  });

插入正确,返回值为空对象.

The insertion happens correctly and the return value is an empty object.

我想退回插入的项目.我找到了这个 doc.但这仅在更新旧值的情况下返回.除了这个,我找不到任何其他有用的信息.

I would like to return the inserted item. I found this doc. But this returns only in case of updating the old value. I could not find any other useful info other than this.

是否有任何解决办法,或者我们只需要使用带有主键的 get 方法进行查询?

Is there any work around or we simply need to query using get method with the primary key?

推荐答案

遗憾的是,您发布的链接是目前唯一真正的答案(API 版本 2012-08-10).PutItem 可能会返回项目就在它们被更新或根本没有更新之前.

The link you posted is, sadly, the only real answer at this time (API Version 2012-08-10). PutItem may return items just before they were updated or none at all.

ReturnValues 参数被多个 DynamoDB 操作使用;但是,PutItem 不能识别除 NONEALL_OLD 之外的任何值.

The ReturnValues parameter is used by several DynamoDB operations; however, PutItem does not recognize any values other than NONE or ALL_OLD.

简而言之,检索插入对象的唯一可靠方法是GetItem,正如你猜测的那样.

In short, the only reliable way to retrieve your inserted object is to GetItem, just as you surmised.

这篇关于如何在dynamoDB中返回插入的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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