Talento90 / mongodb-csharp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MongoDB C# docs

MongoDB for C# developers

  • Repository for the MongoDB C# docs gitbook
  • Build MongoDB queries using the MongoDB C# driver
  • Operators explanations with examples written in C# and node.js (shell)
  • Advanced querying using LINQ

Gitbook πŸ“˜

The docs contain code samples for building MongoDB queries using the MongoDB C# driver an a typed way rather than using BsonDocument.

Example - $unwind operator 🚩

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();

Contributing β˜•

The docs are ofted updated with new samples but you are free to contribute as well. There are two options to do so:

  • Option 1

    • πŸ’‘ Suggest a sample to be added on the docs. Make sure you have done your search either in the docs or the source code before opening the issue. Add some sample data to explain exactly what you are looking for. The issue's title for new samples should have the format Request sample - <short-description>, for example Request sample - add array element
  • Option 2

    • Fix a sample in the docs. 🍴 Fork this repo and open a pull request

License

License

About

License:MIT License


Languages

Language:C# 100.0%