3

I'm trying to migrate my mongoose code/db to dynamoose/dynamodb.

I get the following exception while trying to save custom object:

TypeMismatch: Expected name to be of type object, instead found type object

Here is my sample code on 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;
    }
}

How can I fix this?

KyleMit
  • 30,350
  • 66
  • 462
  • 664
Sanky
  • 193
  • 13

1 Answers1

1

I got it working using this as identified in this issue on Github:

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

Not sure if there is any better way though.

KyleMit
  • 30,350
  • 66
  • 462
  • 664
Sanky
  • 193
  • 13