我正试图将我的猫鼬代码/数据库迁移到dynamodose / dynamodb。
尝试保存自定义对象时出现以下异常:
TypeMismatch:预期名称应为object类型,而不是type类型的对象
这是我在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;
}
}
我该如何解决?
答案 0 :(得分:1)
我按照this issue on Github中的说明使用它来工作:
Man.create({
id:"random",
name: { ...new Name("John", "Martin") }
});
不确定是否还有更好的方法。