Have a schema entry :
PayableAmount: {type: Map}
have also tried
PayableAmount: {type: Object},
const schema = {
Account: {type: String, hashKey: true}
IssueDate: {type: String}
PayableAmount: {type: Object}
}
Model has no extra behavior apart from having a schema
Model.query({
Account: {eq:"someID"},
IssueDate: { le: "Date1", ge: "Date2},
}).exect(callbackFunc);
Query works when I look in debugger and I get the expected return value from dynamo. However, parsing the result for PayableAmount (type M) tries to read it as a type S and throws the following error:
SyntaxError: Unexpected token o in JSON at position 1
at parse (
at dedynamofy (/development/server/node_modules/dynamoose/lib/Attribute.js:470:14)
at Attribute.parseDynamo (/development/server/node_modules/dynamoose/lib/Attribute.js:540:13)
at Schema.parseDynamo (/development/server/node_modules/dynamoose/lib/Schema.js:189:24)
at toModel (/development/server/node_modules/dynamoose/lib/Query.js:240:18)
Should return the Map/Object
Operating System: OSX
Operating System Version: 10.13.6
Node.js version (node -v): v10.8.0
NPM version: (npm -v): 6.4.0
Dynamoose version: "0.8.7"
After looking into this issue more it looks like the problem is that you have not set useDocumentTypes to true in your schema. By default Dynamoose will use string based JSON for document based saving and reading data from DynamoDB. This is due to DynamoDB previously not supporting native lists and maps. You can toggle that option on by setting it in your schema settings, see the documentation here (the useDocumentTypes property).
By default this option is set to false, but the default will be changed to true once PR #376 gets merged in. Currently that PR has failing tests so those need to be fixed before it can be merged in.
I'm closing this issue and related PR for now, since I believe this is working as expected. If toggling that option doesn't work or you have a strong argument for why we should change this behavior please comment and I can help further.
Hope this helps!!
I've tried this and set useDocumentTypes but still get the same error.
@fishcharlie SyntaxError: Unexpected token o in JSON at position 1
The issue happens when another service saves data to dynamo, but I've seen it happen a few different ways. It's critical that dynamo detect that it gets a non-JSON response back that it handles this gracefully. Dynamoose CANNOT depend on being responsible for all saves and all returns all the time.
@brennhill I 100% agree about Dynamoose not depending on being responsible for all saves and all returns all the time. Let me see if I can find some time to do more investigation into this and then I'll get back to you.
@brennhill Two things, can you try to check to see if this is still an issue in Dynamoose v1.0.0. Also, if that doesn't work can you send the DynamoDB JSON for the item that is causing the error?
Now I am getting empty object ( {} ) in version 1.0.0 for keys which are declared as type : Object and useDocumentTypes for the schema is set to true.
@jignesh248 Please see the latest comment in #434. I'm going to be using that issue to track this bug.
@jignesh248 If you want to comment on #434 to help debug that problem, that would be really appreciated.
@brennhill Did you get a chance to look into https://github.com/dynamoosejs/dynamoose/issues/421#issuecomment-428032773?
@brennhill Is there any chance you can create a failing test case for this, then submit a PR for that? The PR will be marked as failing the tests. Once you do that, I will checkout that PR, and do some further investigation.