robhogan / dynamodb-geo.js

A node-friendly typescript port of https://github.com/awslabs/dynamodb-geo
210 stars 97 forks source link

Returning unmarshalled results. #53

Open mvivirito opened 3 years ago

mvivirito commented 3 years ago

I am having issues returning the results of the queries in unmarshalled format for example with projection expression: Querying by radius, looking 100km from Cambridge, UK. [ { geoJson: { S: '{"type":"POINT","coordinates":[-0.13,51.51]}' } } ]

I would like to return: Querying by radius, looking 100km from Cambridge, UK. [ { geoJson: {"type":"POINT","coordinates":[-0.13,51.51]} } } ]

How can I achieve this?

therealsebo commented 3 years ago

You might use the DynamoDB Converter to marshall / unmarshall your data

https://github.com/aws/aws-sdk-js/blob/6efa2feff8d9ec1400a52c749998a747adb58f58/lib/dynamodb/converter.js#L200

mvivirito commented 3 years ago

Where would I call that function. It seems that when I actually use it in my code that I get an empty response. It was showing up at least a couple datapoints prior to using it.

nattapat0255 commented 2 years ago

@mvivirito Your data is an array type but unmarshall function requires an object so you should convert following like below

var shopList = shops.map((shop) => {
                // Convert DynamoDB Json to Normal Json
                return AWS.DynamoDB.Converter.unmarshall(shop)
            })