“DynamoDB查询返回具有语法错误的JSON。”

huangapple go评论54阅读模式
英文:

Dynamodb query returns json with synthax error

问题

以下是您的代码的翻译:

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 数据部分没有发生语法错误。如果您有特定的问题或者需要帮助,请随时告诉我。

英文:

Connected to dynamoDb table using Nodejs, i want to fetch items from table. i tried using query option, it returns json with items but some times it returns Json with synthax error

This is my code

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)

Some times it returns Json with synthax error as given below

{
"Count":117,
"Items":[
... truncated by me ...
{
"pricingTemplate":{
"NULL":true
},
"auditId":{
"S":"7555555_15287101"
},
"importId":{
"S":"8c6976bb-8680-47ce-bcfb-470c8e97740f"
},
"auditStatus":{
"S":"Imported"
},
"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":"Imported"}7555555_15287206"},"importId":{"S":"8c6976bb-8680-47ce-bcfb-470c8e97740f"},"auditStatus":{"S":"Imported"},"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":"Imported"},"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":"Imported"
},
"Id":{
"S":"2161a17f-63c5-4c45-b7b4-9750cc202b23"
},
"recordType":{
"S":"currecy_test_tl"
}
}
],
"ScannedCount":117
}

Edits:
Syntax error at auditStatus":{"S":"Imported"}7555555_15287206"},

答案1

得分: 0

你分享的代码和输出不对齐。代码中使用的文档客户端 dynamoClient 返回本机 JSON。代码中的低级客户端 dynamoDbddb 将返回 DynamoDB JSON,这是您输出并称之为语法错误的内容。

Amazon DynamoDB 命名规则和数据类型

英文:

The code you're sharing and the output you shared are not aligned. The Document Client dynamoClient which you use in the code returns native JSON. The low level client dynamoDb and ddb in your code will return DynamoDB JSON, which is what you are outputting and calling a syntax error.

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html#HowItWorks.DataTypeDescriptors

huangapple
  • 本文由 发表于 2023年5月10日 15:19:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76215854.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定