I would like to share with you the unofficial MongoDB C# docs, a gitbook that contains many samples written with the C# driver in a typed way (not BsonDocument
) which is the prefered way for all C# developers.
Its goal is to cover all types of problems C# developers facing when building MongoDB queries.
Example:
var travelersQueryableCollection = tripsDatabase
.GetCollection<Traveler>(Constants.TravelersCollection)
.AsQueryable();
var linqQuery = travelersQueryableCollection
.SelectMany(t => t.Activities, (t, a) => new
{
age = t.Age,
activity = a
})
.GroupBy(q => q.age)
.Select(g => new { age = g.Key, activities =
g.Select(a => a.activity).Distinct() })
.OrderBy(r => r.age);
var linqQueryResults = await linqQuery.ToListAsync();
I hope you enjoy the docs!!
PS: Feel free to contribute!!