protected virtual void UpsertIntoCollection(RedditPost post) { var collection = GetMongoPostCollection(); collection.ReplaceOne( filter: new BsonDocument("_id", post.Id), options: new ReplaceOptions { IsUpsert = true }, replacement: post.ToBsonDocument()); }
internal IEnumerable <RedditPost> GetRecentPosts(int numPosts) { List <RedditPost> output = new List <RedditPost>(); using (var httpResponse = httpClient.GetAsync(GetRecentPostsRequestUrl(numPosts)).Result) { HttpContent content = httpResponse.Content; if (httpResponse.StatusCode != HttpStatusCode.OK || content == null) { return(output); } RedditPostQueryResponse parsedContent = JsonConvert.DeserializeObject <RedditPostQueryResponse>(content.ReadAsStringAsync().Result); foreach (Post redditComment in parsedContent?.data?.children) { RedditPost toAdd = new RedditPost(redditComment.data); output.Add(toAdd); } } return(output); }