Contributing to the MongoDB C# Driver

June 11, 2026 · View on GitHub

Overview

This repo contains the code and tests for the official MongoDB driver for .NET/C#.

Find or create a tracking issue

Any bug fix should have a tracking issue in Jira. Check for an existing issue first and read any discussion and related PRs; if none exists, create one and wait for guidance from the team before starting work, so you don't build something that won't be accepted.

Note: An issue is not required for a simple typo PR.

Building and testing the code

Build the code and run the tests locally before submitting a pull request. This is straightforward but needs some one-time setup.

Install the .NET SDKs

The driver and tests are multi-targeted across .NET Core 3.1, .NET 6, and .NET 10 (plus .NET Framework 4.7.2 on Windows). Install the .NET 10 SDK to build; running the full test suite also needs the .NET 6 and .NET Core 3.1 runtimes, or you can test a single target.

Install git

Ensure git is installed. It often comes with your IDE or other tools, such as Homebrew on MacOS.

Run MongoDB locally

Note: These instructions were tested on MacOS; they should also work on Linux and Windows.

Most tests run against a local MongoDB in Docker. Run start-mongodb.sh to start the container (via docker-compose.yml) and wait until it is ready:

./start-mongodb.sh

Set MONGODB_URI to mongodb://localhost:56665/?replicaSet=rs0 before running the tests. Edit the compose file to change the port.

Note: Data persists in a Docker volume across restarts. If you change the MongoDB version in the compose file, run docker compose down -v first — the old data files are incompatible with a different server version, and the container will otherwise fail to start (exit code 62).

Atlas (search and vector tests)

The Atlas Local CLI is not suitable for general driver testing because it does not support --setParameter enableTestCommands=1. The search and vector tests targeted at Atlas Search do not run by default; to enable them, set:

  • ATLAS_SEARCH_TESTS_ENABLED=1
  • ATLAS_SEARCH_URI — connection string for your Atlas Local instance

Encryption tests

Download the "Crypt Shared" archive for your platform from MongoDB Enterprise Downloads and extract it:

mkdir -p mongo_crypt_shared_v1-macos-arm64-enterprise-8.0.11
tar -xvzf mongo_crypt_shared_v1-macos-arm64-enterprise-8.0.11.tgz -C mongo_crypt_shared_v1-macos-arm64-enterprise-8.0.11

Then set:

  • CRYPT_SHARED_LIB_PATH — the crypt shared library itself (the .dll, .so, or .dylib file)
  • MONGODB_BINARIES — the folder containing the server binaries

Fork and clone

Fork the repo ("Fork", top right), then clone your fork:

git clone https://github.com/your-github-name/mongo-csharp-driver

Build and run tests

Open CSharpDriver.sln in your IDE, or use the command line:

dotnet build
dotnet test

Single-target runs

dotnet test runs every target by default. Note:

  • The .NET Framework target cannot be used on Mac or Linux.
  • Targets before .NET 6 cannot be used on ARM64.

Restrict to one target with --framework:

dotnet test --framework net10.0

Submit a PR

Push your branch to your fork once all tests pass. Squash multiple commits into one and rebase on the latest upstream first (use the "Sync fork" button on your fork's page).

Syncing your fork with upstream changes

Note: The final commit message must start with the JIRA issue number.

Open a PR with the "Compare and pull request" button on the official repository, explaining what you changed and why.

Appendix: Environment variables

Environment variables used across the codebase. (SET) marks a variable the code sets rather than reads. Paths under src/ are production code; all others are test-only.

Connection & URI

VariablePurposeUsed in
MONGODB_URIPrimary connection string (falls back to MONGO_URI, then mongodb://localhost)CoreTestConfiguration.cs, SmokeTests/.../InfrastructureUtilities.cs, LambdaFunction.cs, BenchmarkHelper.cs, UnifiedTestSpecRunner.cs (SET)
MONGO_URIFallback for MONGODB_URI (default mongodb://localhost)CoreTestConfiguration.cs, SmokeTests/.../InfrastructureUtilities.cs
MONGODB_URI_WITH_MULTIPLE_MONGOSESLoad-balancing / sharded-cluster scenarios (default mongodb://localhost,localhost:27018)CoreTestConfiguration.cs, UnifiedTestSpecRunner.cs (SET), LoadBalancingIntegrationTests.cs (SET)
ATLAS_SEARCH_URIConnection string for Atlas Search integration testsAtlasSearchTestsUtils.cs

AWS authentication

VariablePurposeUsed in
AWS_ACCESS_KEY_IDAWS auth credentialAwsAuthenticationTests.cs, AwsAuthenticationExamples.cs, AwsLambdaExamples.cs
AWS_SECRET_ACCESS_KEYAWS auth credentialAwsAuthenticationTests.cs, AwsAuthenticationExamples.cs, AwsLambdaExamples.cs
AWS_SESSION_TOKENTemporary AWS session credentialAwsAuthenticationExamples.cs, AwsLambdaExamples.cs
AWS_PROFILESelects AWS credential profile (default default)AwsAuthenticationTests.cs
AWS_CONTAINER_CREDENTIALS_RELATIVE_URIECS container credential resolutionAwsAuthenticationTests.cs
AWS_CONTAINER_CREDENTIALS_FULL_URIAlternative ECS container credential endpointAwsAuthenticationTests.cs
AWS_WEB_IDENTITY_TOKEN_FILEWeb identity federationAwsAuthenticationTests.cs
AWS_ECS_ENABLEDDetect ECS environmentAwsAuthenticationTests.cs

FaaS & serverless detection (production code)

All used in src/.../Core/Servers/ServerMonitor.cs and src/.../Core/Connections/ClientDocumentHelper.cs.

VariablePurpose
AWS_EXECUTION_ENVDetect AWS Lambda (prefix AWS_Lambda_); adjusts heartbeat frequency and client metadata
AWS_LAMBDA_RUNTIME_APIDetect AWS Lambda; sets faas.name to aws.lambda
AWS_REGIONPopulate faas.region for Lambda (ClientDocumentHelper.cs only)
FUNCTIONS_WORKER_RUNTIMEDetect Azure Functions; sets faas.name to azure.func
K_SERVICEDetect Google Cloud Run/Functions; sets faas.name to gcp.func
FUNCTION_NAMEDetect Google Cloud Functions
VERCELDetect Vercel; sets faas.name to vercel

X.509 certificates

Both used in CoreTestConfiguration.cs, AuthenticationTests.cs, and EncryptionTestHelper.cs.

VariablePurpose
MONGO_X509_CLIENT_CERTIFICATE_PATHClient certificate for X.509 authentication
MONGO_X509_CLIENT_CERTIFICATE_PASSWORDUnlock password-protected certificate files

GSSAPI / Kerberos

VariablePurposeUsed in
AUTH_GSSAPIEnable and configure Kerberos auth tests (throws if unset when needed)GssapiAuthenticationTests.cs, GssapiSecurityCredentialTests.cs
AUTH_HOSTKerberos authentication endpointGssapiAuthenticationTests.cs

OIDC

VariablePurposeUsed in
OIDC_ENVOIDC test environment (test, azure, gcp, k8s)OidcAuthenticationProseTests.cs, UnifiedEntityMap.cs
OIDC_TOKEN_DIRPath to OIDC token files for testingOidcAuthenticationProseTests.cs, OidcCallbackAdapterFactory.cs (as OIDC_TOKEN_FILE)
TOKEN_RESOURCEOIDC token resource parameterOidcAuthenticationProseTests.cs, UnifiedEntityMap.cs

Client-Side Field Level Encryption (CSFLE)

VariablePurposeUsed in
CRYPT_SHARED_LIB_PATHPath to the MongoDB crypt_shared libraryCoreTestConfiguration.cs, AutoEncryptionTests.cs
LIBMONGOCRYPT_PATHPath to libmongocrypt (production)src/MongoDB.Driver.Encryption/LibraryLoader.cs
MONGODB_BINARIESPath to mongocryptd and other server binaries (default empty)EncryptionTestHelper.cs
FLE_MONGOCRYPTD_PORTCustom port for mongocryptdEncryptionTestHelper.cs
FLE_AWS_KEY / FLE_AWS_SECRETAWS KMS credentials for FLEEncryptionTestHelper.cs
FLE_AWS_KEY2 / FLE_AWS_SECRET2Secondary AWS KMS credentialsEncryptionTestHelper.cs
FLE_AZURE_TENANTID / FLE_AZURE_CLIENTID / FLE_AZURE_CLIENTSECRETAzure KMS credentials for FLEEncryptionTestHelper.cs
FLE_GCP_EMAIL / FLE_GCP_PRIVATEKEYGCP KMS credentials for FLEEncryptionTestHelper.cs
CSFLE_AWS_TEMPORARY_CREDS_ENABLEDEnable AWS temporary credentials for FLE testsEncryptionTestHelper.cs
CSFLE_AWS_TEMP_ACCESS_KEY_ID / CSFLE_AWS_TEMP_SECRET_ACCESS_KEY / CSFLE_AWS_TEMP_SESSION_TOKENTemporary AWS credentials for FLEEncryptionTestHelper.cs
CSFLE_AZURE_KMS_TESTS_ENABLEDEnable Azure KMS integration testsClientEncryptionProseTests.cs
CSFLE_GCP_KMS_TESTS_ENABLEDEnable GCP KMS integration testsClientEncryptionProseTests.cs

GCP & Azure

VariablePurposeUsed in
GCE_METADATA_HOSTCustom GCE metadata server endpoint (default metadata.google.internal)src/.../GcpAuthenticationCredentialsProvider.cs, ClientEncryptionProseTests.cs
AZURE_IMDS_MOCK_ENDPOINTMock Azure Instance Metadata Service endpointClientEncryptionProseTests.cs

Testing & configuration

VariablePurposeUsed in
MONGO_LOGGINGEnable test logging outputCoreTestConfiguration.cs
MONGO_SERVER_SELECTION_TIMEOUT_MSOverride server selection timeout for testsCoreTestConfiguration.cs, DriverTestConfiguration.cs
MONGODB_API_VERSIONSpecify Server API version for testsCoreTestConfiguration.cs
SKIPTESTSTHATREQUIRESERVERSkip integration tests when no server is availableRequireServer.cs
DRIVER_PACKAGE_VERSIONValidate NuGet package versions in smoke testsValidatePackagesVersionTests.cs
OCSP test variablesControl OCSP certificate validation tests (variable name determined per test)OcspIntegrationTests.cs