You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
![]() |
5 days ago | |
---|---|---|
.github/workflows | 2 months ago | |
Release Notes | 5 months ago | |
apidocs | 10 months ago | |
benchmarks/MongoDB.Driver.Benchmarks | 7 months ago | |
evergreen | 2 months ago | |
specifications | 1 month ago | |
src | 5 days ago | |
tests | 5 days ago | |
tools | 4 years ago | |
.editorconfig | 2 months ago | |
.gitattributes | 15 years ago | |
.gitignore | 10 months ago | |
CODEOWNERS | 2 years ago | |
CONTRIBUTING.md | 3 years ago | |
CSharpDriver.sln | 10 months ago | |
CSharpDriver.sln.DotSettings | 5 months ago | |
GitVersion.yml | 2 years ago | |
LICENSE.md | 2 years ago | |
MongoDB.Driver.snk | 1 year ago | |
MongoDB.ruleset | 5 years ago | |
MongoDBLegacy.ruleset | 7 years ago | |
MongoDBLegacyTest.ruleset | 7 years ago | |
MongoDBTest.ruleset | 7 years ago | |
README.md | 3 months ago | |
THIRD-PARTY-NOTICES | 3 years ago | |
build.cake | 2 months ago | |
build.config | 1 year ago | |
build.ps1 | 2 months ago | |
build.sh | 2 months ago | |
packageIcon.png | 1 year ago | |
purls.txt | 5 months ago | |
sbom.json | 5 months ago |
README.md
MongoDB C# Driver
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.