question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTION]TypeMismatch: Expected xxx to be of type object, instead found type object

See original GitHub issue

Hey guys I am pretty new to DynamoDB and dynamoose, trying to migrate my mongoose code/db to dynamoose/dynamodb. I am having this 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-

  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;
    }
}

Can you help me with this?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
fishcharliecommented, Oct 20, 2021

@albertoantunes This is the expected behavior. You can’t store instances of classes in Dynamoose. You have to convert it to a plain JSON object.

1reaction
yashutannacommented, Aug 18, 2020

Hey @fishcharlie I actually have the same issue but under a different schema type:

const Shop = new dynamoose.Schema({
    operatingHours: {
        type: Array,
        schema: [{
          type: Object,
          schema: {
            open: Boolean,
            timeFrom: Number,
            timeTo: Number,
            dayOfWeek: String
          }
        }]
      },
    })

with documentation example from here

this is the error I get for reference:

{
      "message": "Expected operatingHours.0 to be of type object, instead found type object.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "addBusiness"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "name": "TypeMismatch",
          "message": "Expected operatingHours.0 to be of type object, instead found type object.",
          "stacktrace": [
            "TypeMismatch: Expected operatingHours.0 to be of type object, instead found type object.",
            "    at checkTypeFunction (/Users/yashutanna/projects/restaurant-server/node_modules/dynamoose/lib/Document.ts:302:11)",
            "    at /Users/yashutanna/projects/restaurant-server/node_modules/dynamoose/lib/Document.ts:309:7",
            "    at Array.forEach (<anonymous>)",
            "    at checkTypeFunction (/Users/yashutanna/projects/restaurant-server/node_modules/dynamoose/lib/Document.ts:307:11)",
            "    at Array.map (<anonymous>)",
            "    at Function.<anonymous> (/Users/yashutanna/projects/restaurant-server/node_modules/dynamoose/lib/Document.ts:321:111)",
            "    at Generator.next (<anonymous>)",
            "    at fulfilled (/Users/yashutanna/projects/restaurant-server/node_modules/dynamoose/dist/Document.js:5:58)",
            "    at processTicksAndRejections (internal/process/task_queues.js:94:5)"
          ]
        }
      }

I suspect the issue is at this path dynamoose/dist/utils/dynamoose/getValueTypeCheckResult.js but i am struggling to figure out the logic in that file.

I would love a workaround if this is a bigger issue?

Thanks for the awesome library!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamoose- error while saving custom type using object ...
TypeMismatch: Expected name to be of type object, instead found type object. Here is my sample code on nodejs / typescript:
Read more >
Untitled
... yearly https://www.experts-exchange.com/questions/27377241/Object-doesn't- ... Values'-of-report-parameters-'MyField'-doesnt-have-the-expected-type.html ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found