Navigation

MongoDB C#/.NET Driver

Introduction

The official MongoDB C#/.NET Driver provides asynchronous interaction with MongoDB.

Installation

NuGet is the simplest way to get the driver. MongoDB.Driver should be used for all new projects.

For more information, see Installation.

Connect to MongoDB Atlas

To connect to a MongoDB Atlas cluster, use the Atlas connection string for your cluster:

using MongoDB.Bson;
using MongoDB.Driver;
// ...
var client = new MongoClient(
    "mongodb+srv://<username>:<password>@<cluster-address>/test?w=majority"
);
var database = client.GetDatabase("test");

See Connecting for more information.

Compatibility

MongoDB Compatibility

Note

MongoDB 4.2 Feature Availability

The following table specifies which key MongoDB 4.2 features are available in the latest release of the driver:

Feature Available in latest beta release
Distributed Transactions
Callback/Convenient API (Transaction Error Handling)
On-Demand Materialized Views  
Index all paths
Expressive update
Retryable Reads
Retryable Writes On By Default
Keepalive Connections
Client-side Encryption  

The following compatibility table specifies the recommended version(s) of the MongoDB C#/.NET driver for use with a specific version of MongoDB.

The first column lists the driver version(s).

C#/.NET Driver Version MongoDB 4.0 MongoDB 3.6 MongoDB 3.4 MongoDB 3.2 MongoDB 3.0 MongoDB 2.6
Version 2.8
Version 2.7
Version 2.6  
Version 2.5  
Version 2.4    
Version 2.3      
Version 2.2      
Version 2.0        
Version 1.11      
Version 1.10        

The driver does not support older versions of MongoDB.

Language Compatibility

The following compatibility table specifies the recommended version(s) of the MongoDB C#/.NET driver for use with a specific version of .NET.

The first column lists the driver version(s).

Driver Version .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
Version 2.8    
Version 2.7    
Version 2.6    
Version 2.5    
Version 2.4    
Version 2.3    
Version 2.2              
Version 2.0              
Version 1.11          
Version 1.10          

How to get help