func postStory(ctx context.Context, story string) (events.APIGatewayProxyResponse, error) { | |
err := client.Ping(ctx, readpref.Primary()) | |
if err != nil { | |
return handleError(err) | |
} | |
var raw Story // <--- this and the folowing two lines was a big gotcha | |
s := strings.NewReader(story) // ^---> because the type of response.Body is `string` and you need it | |
json.NewDecoder(s).Decode(&raw) // ^---> to be what's defined in your schema/json | |
result, err := collection.InsertOne(ctx, raw) | |
if err != nil { | |
return handleError(err) | |
} | |
/* | |
the following was a big gotcha, | |
cause `result` is type *InsertOneResult | |
and you can't send that as json in your lambda response | |
I had to do some reflection to the result in order to send it. | |
*/ | |
newDbResult = DbResults{nil, result} | |
return handleResultSendDbResponse("InsertOneResult") | |
} |