amazon-dynamodbdynamodb-queries

DynamoDB error when update Date: Unsupported type passed: ... Pass options.convertClassInstanceToMap=true to marshall typeof object as map attribute


When I would like to insert new document into DynamoDB database, Date type property date is inserted without any problem.

 table.create("User", {
     accountName: "johndoe",
     email: "test@test74.test",
     date: new Date(), // Date is inserted without any problem
     username: "johndoe",
     firstName: "John",
     lastName: "Doe"

 }).then(console.log).catch(console.error)

But later, when I would like to update the document date property, I will get the following error:

Error: Unsupported type passed: Mon Oct 31 2022 16:15:25 GMT+0100 (Central European Standard Time).
Pass options.convertClassInstanceToMap=true to marshall typeof object as map attribute.

DynamoDB update code:

table.update("User", {pk: "johndoe"}, {
    set: {
        date: new Date()
    }
}).catch(console.error)

Thanks a lot for each help.


Solution

  • Try with ISO format

    table.update("User", {pk: "johndoe"}, {
        set: {
            date: new Date().toISOString()
        }
    }).catch(console.error)
    

    Also using Date as a partition key is not a good idea :)