【问题标题】:DynamoDB - create Table with nested document in javascriptDynamoDB - 在 javascript 中创建带有嵌套文档的表
【发布时间】:2020-04-13 00:14:51
【问题描述】:

我的问题与java 的问题类似,但需要有关 javascript aws-sdk 的帮助。找不到任何示例。

表结构如下所示:

customer:
  customerId: '12345'
  policies:
  - policyNumber: 12345
    status: active

【问题讨论】:

    标签: javascript amazon-dynamodb aws-sdk


    【解决方案1】:

    您可以尝试使用DocumentClient.put() see documentation。下面是我现有代码中的一个示例,已更新以匹配您的有效负载,但我没有对其进行测试,因为我不想污染我的表。

       import AWS from 'aws-sdk';
    
       const params = {
          TableName: 'TBL_CUSTOMER', //or whatever your table name is
          Item: {
             customerId: '12345',
             policies: {
                policyNumber: 12345,
                status: 'active'
             }
          }
       };
    
       const documentClient = new AWS.DynamoDB.DocumentClient();
    
       const result = await new Promise((resolve, reject) => {
          documentClient.put(params, function (err, data) {
             if (err) reject(err);
             else resolve(data);
          });
       });
       console.log('result:', result);
    

    【讨论】:

    • 我可以创建表语法,因为我发现datamapper 更适合 CrUD。谢谢
    • 基于this answer,只能定义标量类型。如果是这样,将接受这个答案。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-24
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 2018-01-11
    • 1970-01-01
    • 2017-03-08
    相关资源
    最近更新 更多