-
Notifications
You must be signed in to change notification settings - Fork 34
DOCSP-50185: Connection troubleshooting #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
9df45a1
5f7d096
590dc58
19ded8b
c71b622
2f076f5
7582ea1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,206 @@ | ||||||||||
.. _php-connection-troubleshooting: | ||||||||||
|
||||||||||
========================== | ||||||||||
Connection Troubleshooting | ||||||||||
========================== | ||||||||||
|
||||||||||
.. contents:: On this page | ||||||||||
:local: | ||||||||||
:backlinks: none | ||||||||||
:depth: 2 | ||||||||||
:class: singlecol | ||||||||||
|
||||||||||
.. facet:: | ||||||||||
:name: genre | ||||||||||
:values: reference | ||||||||||
|
||||||||||
.. meta:: | ||||||||||
:keywords: code example, disconnected, deployment | ||||||||||
|
||||||||||
This page offers potential solutions to issues that you might encounter | ||||||||||
when using the {+library-short+} to connect to a MongoDB deployment. | ||||||||||
|
||||||||||
.. note:: | ||||||||||
|
||||||||||
This page addresses only connection issues. If you encounter other | ||||||||||
issues when using MongoDB or the {+library-short+}, visit the following resources: | ||||||||||
|
||||||||||
- The :ref:`Issues & Help <php-issues-and-help>` page for | ||||||||||
information about reporting bugs, contributing to the library, and | ||||||||||
finding more resources | ||||||||||
- The :community-forum:`MongoDB Community Forums </tag/php>` for | ||||||||||
questions, discussions, or general technical support | ||||||||||
|
||||||||||
Server Connection Errors | ||||||||||
------------------------ | ||||||||||
|
||||||||||
When an issue occurs when you attempt to connect to a server, the {+driver-short+} | ||||||||||
returns an error message. If this error resembles the following message, it | ||||||||||
indicates that the library cannot connect to a MongoDB deployment: | ||||||||||
|
||||||||||
.. code-block:: none | ||||||||||
:copyable: false | ||||||||||
|
||||||||||
No suitable servers found (`serverSelectionTryOnce` set): | ||||||||||
[connection refused calling hello on 'localhost:27017'] | ||||||||||
|
||||||||||
The following sections describe methods that might help resolve the issue. | ||||||||||
|
||||||||||
Check the Connection String | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thoughts about changing all occurrences of "connection string" to "connection URI"? Seems to be the wording we've been trending towards across our docs. |
||||||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
|
||||||||||
Verify that the hostname and port number in the connection string are both | ||||||||||
accurate. In the sample error message, the hostname is ``127.0.0.1`` and the | ||||||||||
port is ``27017``. The default port value for an instance of MongoDB Server is | ||||||||||
``27017``, but you can configure MongoDB to listen on another port. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
When connecting to a replica set, include all the replica set hosts in | ||||||||||
your connection string. Separate each of the hosts in the connection | ||||||||||
string with a comma. This enables the library to establish a connection if | ||||||||||
one of the hosts is unreachable. | ||||||||||
|
||||||||||
To learn how to specify multiple replica set hosts, see the | ||||||||||
:ref:`Replica Sets <php-connection-replica-set>` section of the | ||||||||||
Choose a Connection Target guide. | ||||||||||
|
||||||||||
Configure the Firewall | ||||||||||
~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
|
||||||||||
If your MongoDB deployment is hosted behind a firewall, ensure the port | ||||||||||
on which MongoDB listens is open in the firewall. If your deployment | ||||||||||
listens on the default network port, ensure that port ``27017`` is | ||||||||||
open in the firewall. If your deployment listens on a different port, | ||||||||||
ensure that port is open on the firewall. | ||||||||||
|
||||||||||
.. warning:: | ||||||||||
|
||||||||||
Do not open a firewall port unless you are sure that it is the one | ||||||||||
that your MongoDB deployment listens on. | ||||||||||
|
||||||||||
Authentication Errors | ||||||||||
--------------------- | ||||||||||
|
||||||||||
The {+driver-short+} may be unable connect to a MongoDB deployment if | ||||||||||
the authorization is not configured correctly. In these cases, the library | ||||||||||
Comment on lines
+83
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll keep as "unable" for style guide reasons |
||||||||||
raises an error message similar to the following message: | ||||||||||
|
||||||||||
.. code-block:: none | ||||||||||
:copyable: false | ||||||||||
|
||||||||||
Authentication failed. | ||||||||||
|
||||||||||
The following sections describe methods that may help resolve the issue. | ||||||||||
|
||||||||||
Check the Credentials Formatting | ||||||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
|
||||||||||
One of the most common causes of authentication issues is invalid | ||||||||||
credentials formatting in the MongoDB connection string. | ||||||||||
|
||||||||||
.. tip:: | ||||||||||
|
||||||||||
To learn more information about using connection strings, | ||||||||||
see :ref:`Connection URI <php-connection-uri>` in the | ||||||||||
Create a MongoDB Client guide. | ||||||||||
|
||||||||||
If your connection string contains a username and password, ensure that | ||||||||||
they are correctly formatted. | ||||||||||
|
||||||||||
.. note:: | ||||||||||
|
||||||||||
If your username or password includes any of the following characters, you | ||||||||||
must `percent-encode <https://tools.ietf.org/html/rfc3986#section-2.1>`__ it: | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
.. code-block:: none | ||||||||||
:copyable: false | ||||||||||
|
||||||||||
: / ? # [ ] @ | ||||||||||
|
||||||||||
Use your percent-encoded username and password in your connection string. | ||||||||||
|
||||||||||
Verify the Authentication Mechanism | ||||||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
|
||||||||||
Ensure that your credentials and authentication mechanism are correct. You can | ||||||||||
specify your authentication credentials in the options of your connection string. | ||||||||||
|
||||||||||
If you use the ``$uriOptions`` parameter to specify an authentication mechanism, | ||||||||||
ensure that you set the ``'authMechanism'`` option to the correct mechanism. The | ||||||||||
following code shows how to specify the ``SCRAM-SHA-1`` authentication mechanism | ||||||||||
in an options parameter: | ||||||||||
|
||||||||||
.. code-block:: php | ||||||||||
:copyable: false | ||||||||||
|
||||||||||
$uriOptions = [ | ||||||||||
'username' => '<username>', | ||||||||||
'password' => '<password>', | ||||||||||
'authSource' => '<authentication database>', | ||||||||||
'authMechanism' => 'SCRAM-SHA-1', | ||||||||||
]; | ||||||||||
|
||||||||||
$client = new MongoDB\Client( | ||||||||||
'mongodb://<hostname>:<port>', | ||||||||||
$uriOptions, | ||||||||||
); | ||||||||||
|
||||||||||
To learn more about specifying authentication mechanisms, see the :ref:`php-auth` | ||||||||||
section. | ||||||||||
|
||||||||||
Verify User Is in Authentication Database | ||||||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
|
||||||||||
When using a username and password-based authentication method, | ||||||||||
the username must be defined in the authentication database. | ||||||||||
|
||||||||||
The default authentication database is the ``admin`` database. | ||||||||||
To use a different database for authentication, specify the | ||||||||||
``authSource`` option in the connection string. | ||||||||||
|
||||||||||
The following example instructs MongoDB to use the ``users`` database | ||||||||||
as the authentication database: | ||||||||||
|
||||||||||
.. code-block:: php | ||||||||||
:copyable: false | ||||||||||
|
||||||||||
$uri = 'mongodb://<username>:<password>@<hostname>:<port>/?authSource=users'; | ||||||||||
$client = new MongoDB\Client($uri); | ||||||||||
|
||||||||||
DNS Resolution Errors | ||||||||||
--------------------- | ||||||||||
|
||||||||||
The {+driver-short+} may be unable to resolve your DNS connection. When this | ||||||||||
norareidy marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
happens, you might receive an error message similar to the following message: | ||||||||||
|
||||||||||
.. code-block:: none | ||||||||||
:copyable: false | ||||||||||
|
||||||||||
No suitable servers found (`serverSelectionTryOnce` set): [Failed to resolve '<host>']. | ||||||||||
|
||||||||||
If the library reports this error, try the methods in the following sections | ||||||||||
to resolve the issue. | ||||||||||
|
||||||||||
Check Database Deployment Availability | ||||||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
|
||||||||||
If you are connecting to MongoDB Atlas and your driver cannot find the DNS | ||||||||||
host of the Atlas database deployment, the database deployment might be paused | ||||||||||
or deleted. | ||||||||||
|
||||||||||
Ensure that the database deployment exists in Atlas. If the cluster is paused, | ||||||||||
you can resume the cluster in the Atlas UI or the | ||||||||||
:atlas:`Atlas command line interface </cli/stable/>`. | ||||||||||
|
||||||||||
To learn how to resume a cluster, see | ||||||||||
:atlas:`Resume One Cluster </pause-terminate-cluster/#resume-one-cluster/>` | ||||||||||
in the Atlas documentation. | ||||||||||
|
||||||||||
Check the Network Addresses | ||||||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
|
||||||||||
Verify that the network addresses or hostnames in your connection string | ||||||||||
are accurate. | ||||||||||
|
||||||||||
If your deployment is hosted on MongoDB Atlas, you can follow the | ||||||||||
:atlas:`Connect to Your Cluster </tutorial/connect-to-your-cluster/>` | ||||||||||
tutorial to find your Atlas connection string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should this be changed? The previous slug matched the title better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a duplicate label - there's another php-connection-uri for this section of the Create a Client page, and it seemed like more of a general overview of URIs