簡體   English   中英

掃描不適用於 Map 或使用 Dynamoose 列出數據類型

[英]Scan not working on Map or List data types using Dynamoose

我將這些數據保存在我的表中

{
 "uid": {
  "S": "poi_ac13603c-4668-42b0-b889-b7b4bf340f67"
 },
 "address": {
  "M": {
   "block": {
    "S": ""
   },
   "buildingName": {
    "S": ""
   },
   "floorNumber": {
    "S": ""
   },
   "postalCode": {
    "S": "247692"
   },
   "streetName": {
    "S": "26A Dempsey Rd"
   },
   "unitNumber": {
    "S": ""
   }
  }
 },
 "archived": {
  "BOOL": false
 },
 "body": {
  "S": ""
 },
 "businessHour": {
  "L": []
 },
 "categories": {
  "L": []
 },
 "categoryDescription": {
  "S": "Food & Beverages"
 },
 "childFriendly": {
  "S": "N"
 },
 "companyDisplayName": {
  "S": ""
 },
 "companyName": {
  "S": ""
 },
 "contact": {
  "M": {
   "otherContactNo": {
    "S": ""
   },
   "primaryContactNo": {
    "S": ""
   },
   "secondaryContactNo": {
    "S": ""
   }
  }
 },
 "createdAt": {
  "N": "1"
 },
 "customPoi": {
  "S": ""
 },
 "dataset": {
  "S": "food_beverages"
 },
 "description": {
  "S": "Tanglin Gin Distillery"
 },
 "endingPoint": {
  "S": ""
 },
 "images": {
  "L": [
   {
    "M": {
     "url": {
      "S": "https://vs-XXX-prod.s3.ap-southeast-1.amazonaws.com/abc56b53-cc2a-4831-bdf2-9ccec12571e1-1201-0530_tanglin-gin-8-medium-imresizer.jpg"
     }
    }
   }
  ]
 },
 "isPrivate": {
  "S": "FALSE"
 },
 "location": {
  "M": {
   "latitude": {
    "N": "1.3055196856574762"
   },
   "longitude": {
    "N": "103.81188168999205"
   }
  }
 },
 "metadata": {
  "M": {}
 },
 "name": {
  "S": "Tanglin Gin Distillery"
 },
 "nearestMrtStation": {
  "S": ""
 },
 "noOfRooms": {
  "S": "0"
 },
 "officialWebsite": {
  "S": "https://tanglin-gin.com"
 },
 "poiType": {
  "S": ""
 },
 "pricing": {
  "M": {
   "adult": {
    "S": ""
   },
   "child": {
    "S": ""
   },
   "others": {
    "S": ""
   },
   "seniorCitizen": {
    "S": ""
   }
  }
 },
 "rating": {
  "N": "0"
 },
 "reviews": {
  "L": []
 },
 "source": {
  "S": "STB"
 },
 "startingPoint": {
  "S": ""
 },
 "thumbnails": {
  "L": []
 },
 "tourDuration": {
  "S": ""
 },
 "updatedAt": {
  "N": "1"
 },
 "wheelChairFriendly": {
  "S": "N"
 }
}

我的模式是這樣的

var schemaDefinition = {
  uid: {
    type: String,
    hashKey: true
  },
  tihUuid: {
    type: String,
    default: ""
  },
  name: {
    type: String,
    required: true
  },
  categoryDescription: {
    type: String,
    default: ""
  },
  archived: {
    type: Boolean,
    default: false
  },
  images: {
    type: Array,
    schema: [
      {
        type: Array,
        schema: [Object]
      }
    ],
    default: []
  },
  thumbnails: {
    type: Array,
    schema: [
      {
        type: Array,
        schema: [Object]
      }
    ],
    default: []
  },
  body: {
    type: String,
    default: ""
  },
  initialDescription: {
    type: String,
    default: ""
  },
  description: {
    type: String,
    default: "",
  },
  shortDescription: {
    type: String,
    default: ""
  },
  poiType: {
    type: String,
    default: ""
  },
  source: {
    type: String,
    default: ""
  },
  dataset: {
    type: String,
    default: ""
  },
  address: {
    type: Object,
    default: {}
  },
  nearestMrtStation: {
    type: String,
    default: ""
  },
  amenities: {
    type: String,
    default: ""
  },
  startDate: {
    type: Date,
    default: ""
  },
  endDate: {
    type: Date,
    default: ""
  },
  companyDisplayName: {
    type: String,
    default: ""
  },
  companyName: {
    type: String,
    default: ""
  },
  contact: {
    type: Object,
    default: {}
  },
  defaultLanguage: {
    type: String,
    default: ""
  },
  eventOrganizer: {
    type: String,
    default: ""
  },
  frequencyOfTours: {
    type: String,
    default: ""
  },
  location: {
    type: Object,
    default: {}
  },
  officialEmail: {
    type: String,
    default: ""
  },
  officialWebsite: {
    type: String,
    default: ""
  },
  price: {
    type: String,
    default: ""
  },
  pricing: {
    type: Object,
    default: {}
  },
  rating: {
    type: Number,
    default: 0.0
  },
  startingPoint: {
    type: String,
    default: ""
  },
  endingPoint: {
    type: String,
    default: ""
  },
  stories: {
    type: String,
    default: ""
  },
  supportedLanguage: {
    type: String,
    default: ""
  },
  tags: {
    type: String,
    default: ""
  },
  tourDuration: {
    type: String,
    default: ""
  },
  typeDescription: {
    type: String,
    default: ""
  },
  minimumAge: {
    type: String,
    default: ""
  },
  notes: {
    type: String,
    default: ""
  },
  origin: {
    type: String,
    default: ""
  },
  reviews: {
    type: Array,
    schema: [
      {
        type: Array,
        schema: [Object]
      }
    ],
    default: []
  },
  businessHour: {
    type: Array,
    schema: [
      {
        type: Array,
        schema: [Object]
      }
    ],
    default: []
  },
  metadata: {
    type: Object,
    default: {}
  },
  temporarilyClosed: {
    type: String,
    default: ""
  },
  createdAt: {
    type: Date,
    default: ""
  },
  updatedAt: {
    type: Date,
    default: ""
  },
  district: {
    type: String,
    default: ""
  },
  categories: {
    type: Array,
    default: []
  },
  advanceBookingRequired: {
    type: Boolean,
    default: false
  },
  priceRange: {
    type: String,
    default: ""
  },
  area: {
    type: String,
    default: ""
  },
  wetWeatherFriendly: {
    type: Boolean,
    default: false
  },
  reasonsToGo: {
    type: Array,
    schema: [String],
    default: []
  },
  staffTips: {
    type: String,
    default: ""
  },
  goodFor: {
    type: Array,
    schema: [String],
    default: []
  },
  accessibility: {
    type: Array,
    schema: [String],
    default: []
  },
  facilities: {
    type: Array,
    schema: [String],
    default: []
  },
  dietaryRestrictions: {
    type: Array,
    schema: [String],
    default: []
  },
  awardWinning: {
    type: Array,
    schema: [String],
    default: []
  },
  cuisine: {
    type: String,
    default: ""
  },
  typeOfCuisine: {
    type: Array,
    schema: [String],
    default: []
  },
  toursAndExperiences: {
    type: Array,
    schema: [String],
    default: []
  },
  descriptiveLabels: {
    type: Object,
    default: {}
  }
}

但是當我掃描時

var response = await klass.scan().exec()

我收到這個錯誤

{
    "errorType": "ParseError",
    "errorMessage": "Unexpected token o in JSON at position 1\nAttribute \"reviews\" of type \"S\" has an invalid value of {\"L\":[]}",
    "trace": [
        "ParseError: Unexpected token o in JSON at position 1",
        "Attribute \"reviews\" of type \"S\" has an invalid value of {\"L\":[]}",
        "    at errorHandlingTransform (/var/task/node_modules/dynamoose/dist/Attribute.js:547:23)",
        "    at dedynamofy (/var/task/node_modules/dynamoose/dist/Attribute.js:564:20)",
        "    at Attribute.parseDynamo (/var/task/node_modules/dynamoose/dist/Attribute.js:646:25)",
        "    at Schema.parseDynamo (/var/task/node_modules/dynamoose/dist/Schema.js:196:38)",
        "    at processTicksAndRejections (internal/process/task_queues.js:97:5)",
        "    at async toModel (/var/task/node_modules/dynamoose/dist/Scan.js:51:9)",
        "    at async Promise.all (index 0)",
        "    at async Response.<anonymous> (/var/task/node_modules/dynamoose/dist/Scan.js:197:38)"
    ]
}

您不是 escaping images的正確值,這會導致其他問題,即您遇到的問題。

改變:

"images": {
    "L": [
      {
        "S": "{\"url\":\""}"
      }
    ]
  },

到:

"images": {
    "L": [
      {
        "S": "{\"url\":\"\"}"
      }
    ]
  },

在第 76 行的圖像下根據您的模式,內部模式應該包含object但它沒有,

images: {
    type: Array,
    schema: [
      {
        type: Array,
        schema: [Object]
      }
    ],
    default: []
  }

但是您的schema下的數據不是 object

    "images": {
      "L": [
        {
          "S": {"url":""}
        }
      ]
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM