Home
Softono
mongo-csharp-driver

mongo-csharp-driver

Open source Apache-2.0 C#
3.2K
Stars
1.3K
Forks
27
Issues
230
Watchers
1 week
Last Commit

About mongo-csharp-driver

The official MongoDB .NET/C driver for connecting .NET applications to MongoDB databases. It provides both untyped BsonDocument and strongly-typed POCO support for CRUD operations, queries, and aggregations. Features include async/await support, LINQ integration for typed queries, BSON serialization, connection string configuration, and access to MongoDB-specific capabilities. The driver follows semantic versioning and is distributed via NuGet. It supports standard MongoClient initialization, database and collection retrieval, and operations like InsertOneAsync and Find with fluent query builders. Comprehensive documentation, API references, and migration guides are available. Bug reports are tracked through MongoDB's JIRA system, and the project is open for community contributions under the Apache 2.0 license.

Platforms

Web Self-hosted Windows

Languages

C#

MongoDB C# Driver

MongoDB.Driver Documentation Documentation License

The official MongoDB .NET/C# driver.

The MongoDB .NET/C# driver follows semantic versioning since v3.0.0 of its releases.

Getting Started

Untyped Documents

using MongoDB.Bson;
using MongoDB.Driver;
var client = new MongoClient("mongodb://localhost:27017");
var database = client.GetDatabase("foo");
var collection = database.GetCollection<BsonDocument>("bar");

await collection.InsertOneAsync(new BsonDocument("Name", "Jack"));

var list = await collection.Find(new BsonDocument("Name", "Jack"))
    .ToListAsync();

foreach(var document in list)
{
    Console.WriteLine(document["Name"]);
}

Typed Documents

using MongoDB.Bson;
using MongoDB.Driver;
public class Person
{
    public ObjectId Id { get; set; }
    public string Name { get; set; }
}
var client = new MongoClient("mongodb://localhost:27017");
var database = client.GetDatabase("foo");
var collection = database.GetCollection<Person>("bar");

await collection.InsertOneAsync(new Person { Name = "Jack" });

var list = await collection.Find(x => x.Name == "Jack")
    .ToListAsync();

foreach(var person in list)
{
    Console.WriteLine(person.Name);
}

Documentation

Questions/Bug Reports

If you’ve identified a security vulnerability in a driver or any other MongoDB project, please report it according to the instructions here.

Contributing

Please see our guidelines for contributing to the driver.

Thank you to everyone who has contributed to this project.