SchemaError:没有为属性给出地图架构:播放列表

问题描述 投票:0回答:1

我正在尝试创建 DynamoDB 架构和用户模型。但每当我调用我的 User 模型时,我的 api 总是会抛出这个错误:

SchemaError: No map schema given for attribute: playlist
。代码如下:

/models/v2/schema.js

const dynamoose = require('dynamoose');

const schemaOpt = { saveUnknown: true, timestamps: true };

const playlistSchema = new dynamoose.Schema({
    "description": String,
    "id": String,
    "name": String,
    "image": String
}, schemaOpt);

const userSchema = new dynamoose.Schema({
    "pk": {
        type: String,
        hashKey: true
    },
    "sk": {
        type: String,
        rangeKey: true
    },
    "playlist": {
        type: Object,
        schema: playlistSchema
    }
}, schemaOpt);

module.exports = userSchema;

/模型/v2/用户

'use strict';

const dynamoose = require('dynamoose');
const userSchema = require('./schema');

const UserModel = dynamoose.model("User", userSchema);


exports.User = UserModel;

使用示例

'use strict';
const rfr = require('rfr');
const { User } = rfr('/models/v2/user')

以上使用代码导致我的API抛出错误

No map schema given for attribute: playlist

javascript amazon-web-services express amazon-dynamodb
1个回答
0
投票

saveUnknown
opt 将允许您存储具有 1 级未知属性的属性
playlist

const schemaOpt = { saveUnknown: ["playlist.*"], timestamps: true }; const userSchema = new dynamoose.Schema({ "pk": { type: String, hashKey: true }, "sk": { type: String, rangeKey: true }, "playlist": Object }, schemaOpt);
    
© www.soinside.com 2019 - 2024. All rights reserved.