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.
![]() |
4 days ago | |
---|---|---|
Release Notes | 5 months ago | |
apidocs | 10 months ago | |
benchmarks/MongoDB.Driver.Benchmarks | 7 months ago | |
evergreen | 3 months ago | |
specifications | 4 months ago | |
src | 4 days ago | |
tests | 4 days ago | |
tools | 4 years ago | |
.editorconfig | 2 years 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 | 1 year ago | |
THIRD-PARTY-NOTICES | 3 years ago | |
build.cake | 9 months ago | |
build.config | 1 year ago | |
build.ps1 | 1 year ago | |
build.sh | 4 months ago | |
packageIcon.png | 1 year ago | |
purls.txt | 5 months ago | |
sbom.json | 5 months ago |
README.md
MongoDB C# Driver
You can get the latest stable release from the official Nuget.org feed or from our github releases page.
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.