|
| 1 | +================== |
| 2 | +Connect to MongoDB |
| 3 | +================== |
| 4 | + |
| 5 | +.. default-domain:: mongodb |
| 6 | + |
| 7 | +.. contents:: On this page |
| 8 | + :local: |
| 9 | + :backlinks: none |
| 10 | + :depth: 2 |
| 11 | + :class: singlecol |
| 12 | + |
| 13 | +Overview |
| 14 | +-------- |
| 15 | + |
| 16 | +Learn how to connect the {+mkc+} to MongoDB using a |
| 17 | +**connection Uniform Resource Identifier (URI)**. A connection URI is a |
| 18 | +string that contains the following information: |
| 19 | + |
| 20 | +- The address of your MongoDB deployment *required* |
| 21 | +- Connection settings *optional* |
| 22 | +- Authentication settings *optional* |
| 23 | +- Authentication credentials *optional* |
| 24 | + |
| 25 | +The following is an example of a connection URI for a MongoDB replica set: |
| 26 | + |
| 27 | +.. code-block:: text |
| 28 | + |
| 29 | + mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?replicaSet=myRepl |
| 30 | + |
| 31 | +To learn more about the connection URI format, see |
| 32 | +:manual:`Connection String URI Format </reference/connection-string/>` in the MongoDB Manual. |
| 33 | + |
| 34 | +How to Connect |
| 35 | +-------------- |
| 36 | + |
| 37 | +Specify a connection URI with the following configuration option in both |
| 38 | +a source and sink connector: |
| 39 | + |
| 40 | +.. code-block:: properties |
| 41 | + |
| 42 | + connection.uri=<your connection uri> |
| 43 | + |
| 44 | +To learn more about this configuration option, see the following resources: |
| 45 | + |
| 46 | +- :doc:`Source connector configuration options </source-connector/configuration-properties/mongodb-connection/>` |
| 47 | +- :doc:`Sink connector configuration options </sink-connector/configuration-properties/mongodb-connection/>` |
| 48 | + |
| 49 | +Connection URI Options |
| 50 | +---------------------- |
| 51 | + |
| 52 | +The {+mkc+} uses the **MongoDB Java driver** to parse your connection URI. |
| 53 | +The MongoDB Java driver is an artifact that enables Java applications like {+kc+} |
| 54 | +to interact with MongoDB. |
| 55 | + |
| 56 | +.. important:: Driver Version |
| 57 | + |
| 58 | + Version {+connector_version+} of the {+mkc+} uses version |
| 59 | + {+connector_driver_version+} of the MongoDB Java driver. |
| 60 | + |
| 61 | +To learn what connection URI options are available in the {+mkc+}, see |
| 62 | +`the MongoDB Java driver Connection guide <{+connector_driver_url_base+}fundamentals/connection/#connection-options>`__. |
| 63 | + |
| 64 | +Authentication |
| 65 | +~~~~~~~~~~~~~~ |
| 66 | + |
| 67 | +All authentication mechanisms available in the MongoDB Java driver are available |
| 68 | +in the {+mkc+}. |
| 69 | + |
| 70 | +The following is an example of a connection URI that authenticates with MongoDB using |
| 71 | +``SCRAM-SHA-256`` authentication: |
| 72 | + |
| 73 | +.. code-block:: text |
| 74 | + |
| 75 | + mongodb://<username>:<password>@<hostname>:<port>/?authSource=<authenticationDb>&authMechanism=SCRAM-SHA-256 |
| 76 | + |
| 77 | +.. important:: Load Secrets |
| 78 | + |
| 79 | + To avoid storing your authentication secrets as plain text in your ``connection.uri`` |
| 80 | + setting, load your secrets from a secure location as your connector starts. |
| 81 | + To learn how to load your secrets as your connector starts, see |
| 82 | + `the Externalize Secrets guide from Confluent <https://docs.confluent.io/platform/current/connect/security.html#externalizing-secrets>`__. |
| 83 | + |
| 84 | +To learn what authentication mechanisms are available, see |
| 85 | +`the MongoDB Java driver Authentication Mechanisms guide <{+connector_driver_url_base+}fundamentals/auth/#mechanisms>`__. |
| 86 | + |
| 87 | +To learn more about authentication in the {+mkc+}, see the |
| 88 | +:doc:`Security and Authentication guide </security-and-authentication>`. |
0 commit comments