MongoDB驱动 > C#和.NET驱动程序
官方的MongoDB C#/。NET驱动程序提供了与MongoDB的异步交互。
NuGet
是获取驱动程序的最简单方法。对所有新项目使用
MongoDB.Driver。
有关更多信息,请参见安装。
要连接到MongoDB Atlas集群,请为集群使用 Atlas连接字符串:
using MongoDB.Bson;
using MongoDB.Driver;
// ...
var client = new MongoClient(
"mongodb+srv://<username>:<password>@<cluster-address>/test?w=majority"
);
var database = client.GetDatabase("test");
有关 更多信息,请参见连接。
C#/。NET驱动程序版本 | MongoDB 4.2 | MongoDB 4.0 | MongoDB 3.6 | MongoDB 3.4 | MongoDB 3.2 | MongoDB 3.0 | MongoDB 2.6 |
---|---|---|---|---|---|---|---|
版本2.10 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2.9版 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
2.8版 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
2.7版 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
2.6版 | ✓ | ✓ | ✓ | ✓ | ✓ | ||
版本2.5 | ✓ | ✓ | ✓ | ✓ | ✓ | ||
版本2.4 | ✓ | ✓ | ✓ | ✓ | |||
版本2.3 | ✓ | ✓ | ✓ | ||||
版本2.2 | ✓ | ✓ | ✓ | ||||
版本2.0 | ✓ | ✓ | |||||
版本1.11 | ✓ | ✓ | ✓ | ||||
版本1.10 | ✓ | ✓ |
该驱动程序不支持旧版本的MongoDB。
驱动版本 | .NET 3.5 | .NET 4.0 | .NET 4.5 | .NET 4.6 | .NET 4.7 | .NET 4.8 | .NET Core 1.0 | .NET Core 1.1 | .NET Core 2.0 | .NET Core 2.1 | .NET Core 2.2 |
---|---|---|---|---|---|---|---|---|---|---|---|
版本2.10 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
2.9版 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
2.8版 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
2.7版 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
2.6版 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
版本2.5 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
版本2.4 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
版本2.3 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
版本2.2 | ✓ | ✓ | ✓ | ✓ | |||||||
版本2.0 | ✓ | ✓ | ✓ | ✓ | |||||||
版本1.11 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||||
版本1.10 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |