Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type mismatch for key id #17

Closed
ubiquitousthey opened this issue Dec 1, 2014 · 10 comments
Closed

Type mismatch for key id #17

ubiquitousthey opened this issue Dec 1, 2014 · 10 comments

Comments

@ubiquitousthey
Copy link

Saving the same item causes the following error the second time it is saved.

{"message":"One or more parameter values were invalid: Type mismatch for key id expected: S actual: M","code":"ValidationException","time":"2014-12-01T00:03:13.754Z","statusCode":400,"retryable":false,"retryDelay":0}}

{ TableName: 'companies',
Item:
{ name: 'Edenic Confluence, LLC',
data: { this: 1, that: 'abc' },
id: '7c67562e-bddc-4931-b867-c78ed2862f56' } }

If I restart node.js, it works again the first time.

@ubiquitousthey
Copy link
Author

BTW, the id is a uuid generated each time by node-uuid.

@raymolin
Copy link
Contributor

Can you confirm what item you're saving? It seems to me right now that you may be saving the first time as '' and the second time as {S: ''}. The reason why you're getting the type mismatch is because the library treats object types as Map types.

@zachpetch
Copy link

I know this is old, but in case anyone else comes here from a google search for a similar issue (like I did), I thought I'd share my solution.

The error is saying that DynamoDB expected a string for the uuid, but it is getting something else.
According to this from the dynamodb docs, S is dynamodb's string, and, as raymolin said, M is a map (like an object or model). Thus, the uuid being sent must not be a string, but a model/object/map. Once that's fixed, this should work fine.

@Joggibears
Copy link

Dude, Thank you!

@theivanfranco
Copy link

You rock! Thank you.

@sumosam
Copy link

sumosam commented Mar 8, 2019

Thank you zachpetch!

@artursvonda
Copy link

For those coming here to look for solutions:
My issue was that I was using AWS.DynamoDB.DocumentClient instead of AWS.DynamoDB (code generated by the Amplify so I didn't notice) and was providing all attribute values manually as I'm used to ({Key: {S: "the key"}} instead of {Key: "the key"}) and that caused the {S: "the key"} to be turned into Map value instead of key value. Hope this helps someone.

@mrmatos6837
Copy link

@artursvonda I literaly logged in just to thank you for this!

@zacyang
Copy link

zacyang commented Jul 15, 2020

What sad was I had the same issue in 2020....consistency AWS...

so in short:
as @artursvonda pointed out,
dynamodb accept item with dynamodb schema format {Key: {S: "the key"}}, but if you are using AWS.DynamoDB.DocumentClient this was simplified by the lib so you can just provide a plain json. Meaning no need for AWS.DynamoDB.Converter.marshall(event.Input)

@lsdeva
Copy link

lsdeva commented Aug 21, 2023

Got the same issue. Fixed by removing data type declaration.

before
const params = {
Item: {
"UserId": {
S: "gdhgfh"
},
"Age": {
N: "28"
},
"Height": {
N: "72"
},
"Income": {
N: "2500"
}
},
TableName: "new-table"
};

after:
const command = new PutCommand({
Item: {
"UserId": "gdhgfh",
"Age": "28",
"Height": "72",
"Income": "2500"
},
TableName: "new-table"
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants