NodeJS Dynamodb查询返回json并出现synthax错误

bqf10yzr  于 2023-05-17  发布在  Node.js
关注(0)|答案(1)|浏览(134)

使用Nodejs连接到dynamoDb表,我想从表中获取项目。我尝试使用查询选项,它返回json与项目,但有时它返回json与synthax错误
这是我的代码

let ddb = new AWS.DynamoDB(config)
export const dynamoDb = ddb
export const dynamoClient = new AWS.DynamoDB.DocumentClient({
  service: dynamoDb
})

let params = {
    TableName: auditTable,
    IndexName: 'importId-auditStatus-index',
    KeyConditionExpression: 'importId = :importId and auditStatus = :auditStatus',
    ExpressionAttributeValues: {
      ':importId': importId,
      ':auditStatus' : 'Imported'
    }
  }

let response = await dynamoClient.query(params, function(err, data) {
    if (err) {
      console.log("Error", err);
    } else {
      return data;
    }
  }).promise();
  console.log("response",response)

有时它会返回Json并显示synthax错误,如下所示
{"Count ":117," Items ":[...被我截断了{"pricingTemplate ":{"NULL":true},"auditId":{" S ":"7555555_15287101 "}," importId ":{"S":" 8c6976bb-8680 - 47ce-bcfb-470c8e97740f "},"auditStatus":{" S ":"已导入"}," Id ":{"S":" 420f50cb-3d03 - 49cb-b1da-1a36aa099e6c "},"recordType":{" S ":"currecy_test_tl "}},{" pricingTemplate":{"NULL ":true}," auditId ":{" S":" 7555555_15287164 "},"importId":{"S ":"8c6976bb-8680 - 47ce-bcfb-470c8e97740f "}," auditStatus ":{" S":"已导入"} 755555_15287206 "},"importId":{"S":" 8c6976bb-8680 - 47ce-bcfb-470c8e97740f "}," auditStatus":{" S":"已导入"}," Id":{" S":" e7042719-fa77 - 4939 - 9d05-ad41f3bdc7dc "}," recordType":{" S":" currecy_test_tl "}},{" pricingTemplate":{" NULL":true}," auditId":{" S":" 7555555_15287155 "}," importId":{" S":" 8c6976bb-8680 - 47ce-bcfb-470c8e97740f "}," auditStatus":{" S":"已导入"}," Id":{" S":" bee5d2e3 - 60cf-4ecf-8249-d25de6e8c28a "}," recordType":{" S":" currecy_test_tl "}},{" pricingTemplate":{" NULL":true}," auditId":{" S":" 7555555_15287111 "}," importId":{" S":" 8c6976bb-8680 - 47ce-bcfb-470c8e97740f "}," auditStatus":{" S":"已导入"}," Id":{" S":" 2161a17f-63c5 - 4c45-b7b4 - 9750cc202b23 "}," recordType":{" S":" currecy_test_tl "}}]," ScannedCount":117}
编辑:auditStatus":{"S":"Imported"}7555555_15287206"},处的语法错误

u3r8eeie

u3r8eeie1#

您共享的代码和您共享的输出未对齐。您在代码中使用的文档客户端dynamoClient返回原生JSON。代码中的低级客户端dynamoDbddb将返回DynamoDB JSON,这是您正在输出并调用语法错误的内容。
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html#HowItWorks.DataTypeDescriptors

相关问题