I currently have a mongodb filled with restaurants. Each restaurants has an array with review objects. I'm trying to retrieve a list of each review object in C#, but I can't get it to work.
So to clarify, I can get a restaurant, but I can't seem to get an List of just the review objects in C#.
I tried this, but it just returns the restaurant objects to me:
var coll = Database.GetCollection<Restaurant>("restaurants")
.Aggregate()
.Unwind(x => x.reviews);
var result = await coll.ToListAsync();
foreach(var r in result)
{
Console.WriteLine(r.ToString());
}
This is my restaurant class:
public class Restaurant
{
[BsonId]
private ObjectId _id { get; set; }
[BsonElement("name")]
public string name { get; set; }
[BsonElement("reviews")]
public List<Review> reviews { get; set; }
public Restaurant(string name)
{
_id = ObjectId.GenerateNewId();
this.name = name;
reviews = new List<Review>();
}
public void addReview(Review r)
{
reviews.Add(r);
}
public void removeReview(Review r)
{
reviews.Remove(r);
}
}
Any help would be greatly appreciated!