Last active
December 30, 2019 21:43
-
-
Save JNaeemGitonga/d56c659b46287a148e2c413f2f272b88 to your computer and use it in GitHub Desktop.
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 getStories(ctx context.Context) (events.APIGatewayProxyResponse, error) { | |
err := client.Ping(ctx, readpref.Primary()) | |
if err != nil { | |
return handleError(err) | |
} | |
cursor, err := collection.Find(ctx, bson.D{}) | |
defer cursor.Close(ctx) | |
if err != nil { | |
return handleError(err) | |
} | |
// stories is the array of stories that will get fetched | |
var stories []Story | |
for cursor.Next(ctx) { | |
// create a value into which the single document can be decoded | |
var story Story | |
err := cursor.Decode(&story) | |
if err != nil { | |
return handleError(err) | |
} | |
stories = append(stories, story) | |
} | |
return marshalJSONAndSend(stories) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment