From f7aa29b883b48bb9d287a950eaa632fe0c5b72c0 Mon Sep 17 00:00:00 2001 From: Melanie Ballard Date: Fri, 6 Jun 2025 14:52:00 -0400 Subject: [PATCH 1/3] DOCSP-49972 Checking File creation for Go connection target --- source/fundamentals/connections.txt | 1 + .../connections/connection-target.txt | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 source/fundamentals/connections/connection-target.txt diff --git a/source/fundamentals/connections.txt b/source/fundamentals/connections.txt index 7bb9145e..addd1213 100644 --- a/source/fundamentals/connections.txt +++ b/source/fundamentals/connections.txt @@ -28,6 +28,7 @@ Learn how to use the {+driver-short+} to configure your application's connection to a MongoDB deployment in the following sections: - :ref:`golang-connection-guide` +- :ref:`golang-connection-targets` - :ref:`golang-connection-options` - :ref:`golang-network-compression` - :ref:`golang-tls` diff --git a/source/fundamentals/connections/connection-target.txt b/source/fundamentals/connections/connection-target.txt new file mode 100644 index 00000000..ec49c2ca --- /dev/null +++ b/source/fundamentals/connections/connection-target.txt @@ -0,0 +1,40 @@ +.. _golang-connection-targets: + +========================== +Choose a Connection Target +========================== + +Overview +-------- + +In this guide, you can learn how to use a connection string and a +``MongoClient`` object to connect to different types of MongoDB deployments. + +.. tip:: + + To learn more about how to retrieve or format your connection string, see + the :ref:`Connection URI ` guide in + the Go Connection Guide. + +Atlas +----- + +To connect to a MongoDB deployment on Atlas, include the following elements in your +connection string: + +- URL of your Atlas cluster +- MongoDB username +- MongoDB password + +Then, pass your connection string to the ``MongoClient`` constructor. + +When you connect to Atlas, we recommend using the {+stable-api+} client option to avoid +breaking changes when Atlas upgrades to a new version of {+mdb-server+}. +To learn more about the {+stable-api+} feature, see the :ref:`` +guide. + +The following code shows how to use the {+driver-short+} to connect to an Atlas cluster. The +code also uses the ``server_api`` field to specify a {+stable-api+} version. + +.. _go-connection-example-code: + From 6141ba3281d4cf99ff445306c930f02fa5631135 Mon Sep 17 00:00:00 2001 From: Melanie Ballard Date: Fri, 6 Jun 2025 15:10:32 -0400 Subject: [PATCH 2/3] DOCSP-49972 toc tree and code example --- source/fundamentals/connections.txt | 1 + .../connections/connection-target.txt | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/source/fundamentals/connections.txt b/source/fundamentals/connections.txt index addd1213..97d062e2 100644 --- a/source/fundamentals/connections.txt +++ b/source/fundamentals/connections.txt @@ -10,6 +10,7 @@ Connections .. toctree:: Connection Guide + Choose a Connection Target Connection Options Network Compression Configure TLS diff --git a/source/fundamentals/connections/connection-target.txt b/source/fundamentals/connections/connection-target.txt index ec49c2ca..d0342753 100644 --- a/source/fundamentals/connections/connection-target.txt +++ b/source/fundamentals/connections/connection-target.txt @@ -4,6 +4,20 @@ Choose a Connection Target ========================== +.. facet:: + :name: genre + :values: tutorial + +.. meta:: + :description: Learn how to select connection targets for the MongoDB Go Driver. + :keywords: + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + Overview -------- @@ -13,7 +27,7 @@ In this guide, you can learn how to use a connection string and a .. tip:: To learn more about how to retrieve or format your connection string, see - the :ref:`Connection URI ` guide in + the :ref:`Connection URI ` guide in the Go Connection Guide. Atlas @@ -38,3 +52,7 @@ code also uses the ``server_api`` field to specify a {+stable-api+} version. .. _go-connection-example-code: +.. literalinclude:: /includes/fundamentals/code-snippets/srv.go + :language: go + + From 759bd80c6b477f8b1452ff957cc9eb49452d19f2 Mon Sep 17 00:00:00 2001 From: Melanie Ballard Date: Fri, 6 Jun 2025 15:49:02 -0400 Subject: [PATCH 3/3] DOCSP-49972 Updating all targets on connection targets page --- .../connections/connection-target.txt | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/source/fundamentals/connections/connection-target.txt b/source/fundamentals/connections/connection-target.txt index d0342753..30abc412 100644 --- a/source/fundamentals/connections/connection-target.txt +++ b/source/fundamentals/connections/connection-target.txt @@ -55,4 +55,53 @@ code also uses the ``server_api`` field to specify a {+stable-api+} version. .. literalinclude:: /includes/fundamentals/code-snippets/srv.go :language: go +Local Deployments +----------------- +.. include:: /includes/localhost-connection.rst + +Replica Set +----------- + +A MongoDB replica set deployment is a group of connected instances that +store the same set of data. This configuration provides data +redundancy and high data availability. + +To connect to a replica set deployment, specify the hostname and port numbers +of each instance, separated by commas, and the replica set name as the value +of the ``replicaSet`` parameter in the connection string. In the following +example, the hostnames are ``host1``, ``host2``, and ``host3``, and the +port numbers are all ``27017``. The replica set name is ``myRS``. + +.. code-block:: none + + mongodb://host1:27017,host2:27017,host3:27017/?replicaSet=myRS + +When connecting to a replica set, the driver takes the following actions by default: + +- Discovers all replica set members when given the address of any one member. +- Dispatches operations to the appropriate member, such as instructions + to write against the **primary**. + +.. tip:: + + You can specify just one host to connect to a replica set. + However, to ensure connectivity when the specified host + is unavailable, you should provide the full list of hosts. + +Direct Connection +````````````````` + +To force operations on the host designated in the connection URI, +specify the ``directConnection`` option. Direct connections exhibit the +following behavior: + +- They don't support SRV strings. +- They fail on writes when the specified host is not the **primary**. +- They require you to specify a :manual:`secondary read preference + ` when the + specified host isn't the **primary** node. + +.. note:: Replica Set in Docker + + .. sharedinclude:: dbx/docker-replica-set.rst \ No newline at end of file