【问题标题】:Dynamoose- error while saving custom type using object: Expected xxx to be of type object, instead found type objectDynamoose - 使用对象保存自定义类型时出错:预期 xxx 为对象类型,而不是找到类型对象
【发布时间】:2020-11-13 05:23:49
【问题描述】:

我正在尝试将我的 mongoose 代码/db 迁移到 dynamoose/dynamodb。

尝试保存自定义对象时出现以下异常:

TypeMismatch:预期名称为对象类型,而不是找到类型对象

这是我在 nodejs / typescript 上的示例代码:

import dynamoose from "dynamoose";

export = {
    run: async() => {
        dynamoose.aws.sdk.config.update({ 
            "accessKeyId": "AKID", 
            "secretAccessKey": "SECRET", 
            "region": "us-east-1" 
        }); 
        dynamoose.aws.ddb.local();
        const Man = dynamoose.model('Man', {
            id: String,
            name: {
                type: Object,
                schema: {
                    firstname: String,
                    lastname: String
                }
            }});
        Man.create({
            id:"random",
            name: new Name("John", "Martin")
        });
    }
}.run();

class Name {
    firstname: string;
    lastname: string;
    constructor(firstname: string, lastname: string){
        this.firstname = firstname;
        this.lastname = lastname;
    }
}

我该如何解决这个问题?

【问题讨论】:

    标签: amazon-dynamodb dynamoose


    【解决方案1】:

    我使用 this issue on Github 中标识的它来工作:

    Man.create({
        id:"random",
        name: { ...new Name("John", "Martin") }
    });
    

    不知道有没有更好的办法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-02
      • 2021-01-29
      • 2014-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多