socks
For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt
<!-- Tab options on this page. Append to the .md URL to filter: ?tabs=<id,...> select specific tabs (e.g. ?tabs=nodejs,shell) ?allTabs=true include every tab (no param) default: one tab per tabset
Available tabs: other tabs: proxy-settings, connection-string -->
Connect to MongoDB by Using a SOCKS5 Proxy
Overview
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.
SOCKS5 Proxy Settings
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
MongoClientSettingsinstance, set theSocks5ProxySettingsproperty to an instance of theSocks5ProxySettingsclass.
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. |
Example
The following example shows how to connect to a MongoDB deployment by using a SOCKS5 proxy:
Socks5ProxySettings
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);
API Documentation
To learn more about the methods and types discussed in this guide, see the following API documentation:
