Docs Menu
Docs Home
/ / /
C#/.NET Driver
/

Connect to MongoDB by Using a SOCKS5 Proxy

In this guide, you can learn how to connect to MongoDB by using a SOCKS5 proxy. SOCKS5 is a standardized protocol for communicating with network services through a proxy server.

Tip

To learn more about the SOCKS5 protocol, see the Wikipedia entry on SOCKS.

The proxy settings specify the SOCKS5 proxy server address and your authentication credentials. You can specify these settings in the following ways:

  • Include them in your connection URI as parameters.

  • On your MongoClientSettings instance, set the Socks5ProxySettings property to an instance of the Socks5ProxySettings class.

The following table describes the SOCKS5 proxy settings:

Setting
Description

Host

Specifies the SOCKS5 proxy IPv4 address, IPv6 address, or hostname. You must provide this value to connect to a SOCKS5 proxy.

Port

Specifies the TCP port number of the SOCKS5 proxy server.

Default: 1080

Authentication

Specifies the authentication settings the SOCKS5 proxy server. You can use the UsernamePassword() method of the Socks5AuthenticationSettings class to create authentication settings with your credentials.

The following example shows how to connect to a MongoDB deployment by using a SOCKS5 proxy:

var settings = new MongoClientSettings.FromConnectionString("<connection URI>");
var proxySettings = new Socks5ProxySettings(
"<proxy host>", 1, Socks5AuthenticationSettings.UsernamePassword("<username>", "<password>"));
settings.Socks5ProxySettings = proxySettings;
var client = new MongoClient(settings);
var connectionURI = "mongodb://localhost:27017/" +
"?proxyHost=<proxyHost>" +
"&proxyPort=<proxyPort>" +
"&proxyUsername=<proxyUsername>" +
"&proxyPassword=<proxyPassword>";
var client = new MongoClient(connectionURI);

To learn more about the methods and types discussed in this guide, see the following API documentation:

Back

TLS/SSL

On this page