|
| 1 | +This page offers potential solutions to issues that you might encounter |
| 2 | +when using the {+driver-long+} to connect to a MongoDB deployment. |
| 3 | + |
| 4 | +|non-connection-issue-callout| |
| 5 | + |
| 6 | +Server Connection Errors |
| 7 | +------------------------ |
| 8 | + |
| 9 | +When an issue occurs when you attempt to connect to a server, the {+driver-short+} |
| 10 | +returns an error message. If this error resembles the following message, it |
| 11 | +indicates that the driver cannot connect to a MongoDB deployment: |
| 12 | + |
| 13 | +|server-selection-timeout-error| |
| 14 | + |
| 15 | +The following sections describe methods that might help resolve the issue. |
| 16 | + |
| 17 | +|check-connection-string-anchor| |
| 18 | + |
| 19 | +Check the Connection String |
| 20 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 21 | + |
| 22 | +Verify that the hostname and port number in the connection string are both |
| 23 | +accurate. In the sample error message, the hostname is ``127.0.0.1`` and the |
| 24 | +port is ``27017``. The default port value for an instance of MongoDB Server is |
| 25 | +``27017``, but you can configure MongoDB to listen on another port. |
| 26 | + |
| 27 | +When connecting to a replica set, include all the replica set hosts in |
| 28 | +your connection string. Separate each of the hosts in the connection |
| 29 | +string with a comma. This enables the driver to establish a connection if |
| 30 | +one of the hosts is unreachable. |
| 31 | + |
| 32 | +|multiple-hosts-connection-guide-link| |
| 33 | + |
| 34 | +|configure-firewall-anchor| |
| 35 | + |
| 36 | +Configure the Firewall |
| 37 | +~~~~~~~~~~~~~~~~~~~~~~ |
| 38 | + |
| 39 | +If your MongoDB deployment is hosted behind a firewall, ensure the port |
| 40 | +on which MongoDB listens is open in the firewall. If your deployment |
| 41 | +listens on the default network port, ensure that port ``27017`` is |
| 42 | +open in the firewall. If your deployment listens on a different port, |
| 43 | +ensure that port is open on the firewall. |
| 44 | + |
| 45 | +.. warning:: |
| 46 | + |
| 47 | + Do not open a firewall port unless you are sure that it is the one |
| 48 | + that your MongoDB deployment listens on. |
| 49 | + |
| 50 | +|check-the-number-of-connections-anchor| |
| 51 | + |
| 52 | +Check the Number of Connections |
| 53 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 54 | + |
| 55 | +Each |mongo-client-class| instance supports a maximum number of concurrent open |
| 56 | +connections in its connection pool. The configuration parameter |max-pool-size-param| |
| 57 | +defines this value and is set to |max-pool-size-default| by default. If the |
| 58 | +number of open connections is equal to |max-pool-size-param|, the server waits until |
| 59 | +a connection becomes available. If this wait time exceeds the |max-idle-time-param| |
| 60 | +value, the driver responds with an error. |
| 61 | + |
| 62 | +|connection-pools-learn-more| |
| 63 | + |
| 64 | +|authentication-error-anchor| |
| 65 | + |
| 66 | +Authentication Errors |
| 67 | +--------------------- |
| 68 | + |
| 69 | +The {+driver-short+} may be unable connect to a MongoDB deployment if |
| 70 | +the authorization is not configured correctly. In these cases, the driver |
| 71 | +raises an error message similar to the following message: |
| 72 | + |
| 73 | +|scram-failure-error| |
| 74 | + |
| 75 | +The following sections describe methods that may help resolve the issue. |
| 76 | + |
| 77 | +|check-credentials-formatting-anchor| |
| 78 | + |
| 79 | +Check the Credentials Formatting |
| 80 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 81 | + |
| 82 | +One of the most common causes of authentication issues is invalid |
| 83 | +credentials formatting in the MongoDB connection string. |
| 84 | + |
| 85 | +|learn-more-connection-string-admonition| |
| 86 | + |
| 87 | +If your connection string contains a username and password, ensure that |
| 88 | +they are correctly formatted. |
| 89 | + |
| 90 | +.. note:: |
| 91 | + |
| 92 | + If your username or password includes any of the following characters, you |
| 93 | + must `percent-encode <https://tools.ietf.org/html/rfc3986#section-2.1>`__ it: |
| 94 | + |
| 95 | + .. code-block:: none |
| 96 | + :copyable: false |
| 97 | +
|
| 98 | + : / ? # [ ] @ |
| 99 | +
|
| 100 | + Use your percent-encoded username and password in your connection string. |
| 101 | + |
| 102 | +|percent-encode-example| |
| 103 | + |
| 104 | +|verify-authentication-mechanism-anchor| |
| 105 | + |
| 106 | +Verify the Authentication Mechanism |
| 107 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 108 | + |
| 109 | +Ensure that your credentials and authentication mechanism are correct. You can |
| 110 | +specify your authentication credentials in the options of your connection string. |
| 111 | + |
| 112 | +|credentials-provider-alternative-method-description| |
| 113 | + |
| 114 | +|authentication-guide-reference| |
| 115 | + |
| 116 | +|verify-authentication-database-anchor| |
| 117 | + |
| 118 | +Verify User Is in Authentication Database |
| 119 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 120 | + |
| 121 | +When using a username and password-based authentication method, |
| 122 | +the username must be defined in the authentication database. |
| 123 | + |
| 124 | +The default authentication database is the ``admin`` database. |
| 125 | +To use a different database for authentication, specify the |
| 126 | +``authSource`` option in the connection string. |
| 127 | + |
| 128 | +The following example instructs MongoDB to use the ``users`` database |
| 129 | +as the authentication database: |
| 130 | + |
| 131 | +|authsource-param-code-block| |
| 132 | + |
| 133 | +|dns-resolution-anchor| |
| 134 | + |
| 135 | +DNS Resolution Errors |
| 136 | +--------------------- |
| 137 | + |
| 138 | +The {+driver-short+} may be unable to resolve your DNS connection. When this |
| 139 | +happens, you might receive an error message similar to the following message: |
| 140 | + |
| 141 | +|dns-error-message| |
| 142 | + |
| 143 | +If the driver reports this error, try the methods in the following sections |
| 144 | +to resolve the issue. |
| 145 | + |
| 146 | +Check Database Deployment Availability |
| 147 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 148 | + |
| 149 | +If you are connecting to MongoDB Atlas and your driver cannot find the DNS |
| 150 | +host of the Atlas database deployment, the database deployment might be paused |
| 151 | +or deleted. |
| 152 | + |
| 153 | +Ensure that the database deployment exists in Atlas. If the cluster is paused, |
| 154 | +you can resume the cluster in the Atlas UI or the |
| 155 | +:atlas:`Atlas command line interface </cli/stable/>`. |
| 156 | + |
| 157 | +To learn how to resume a cluster, see |
| 158 | +:atlas:`Resume One Cluster </pause-terminate-cluster/#resume-one-cluster/>` |
| 159 | +in the Atlas documentation. |
| 160 | + |
| 161 | +Check the Network Addresses |
| 162 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 163 | + |
| 164 | +Verify that the network addresses or hostnames in your connection string |
| 165 | +are accurate. |
| 166 | + |
| 167 | +If your deployment is hosted on MongoDB Atlas, you can follow the |
| 168 | +:atlas:`Connect to Your Cluster </tutorial/connect-to-your-cluster/>` |
| 169 | +tutorial to find your Atlas connection string. |
0 commit comments