amazon-dynamodbdynamoose

Dynamoose- error while saving custom type using object: Expected xxx to be of type object, instead found type object


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?


Solution

  • 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.