Last active
December 29, 2019 20:59
-
-
Save JNaeemGitonga/34cd6f149ba1a9f0d68465e2b9012d77 to your computer and use it in GitHub Desktop.
func updateStory(update string) (events.APIGatewayProxyResponse, error) {...}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func updateStory(ctx context.Context, update string) (events.APIGatewayProxyResponse, error) { | |
var raw Story // <--- this line and the following two are important here because if we didn't do this | |
data := []byte(update) // we wouldn't be able to use the incoming data as is since it is of type `string`. | |
if err := json.Unmarshal(data, &raw); err != nil { | |
handleError(err) | |
} | |
filter := bson.D{{"_id", raw.ID}} // <-- this is how we access those objects | |
upDate := bson.D{{"$set", bson.D{{"likes", raw.Likes}}}} | |
result, err := collection.UpdateOne(ctx, filter, upDate) | |
if err != nil { | |
return handleError(err) | |
} | |
newDbResult = DbResults{result, nil} | |
return handleResultSendDbResponse("UpdateResult") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment