Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lindseymoore committed Aug 9, 2024
1 parent f1d1edc commit ff56653
Showing 1 changed file with 9 additions and 108 deletions.
117 changes: 9 additions & 108 deletions source/connect/mongoclient.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ To connect to a MongoDB deployment, you need two things:
- A **connection URI**, also known as a *connection string*, which tells the {+driver-short+}
which MongoDB deployment to connect to.
- A **MongoClient** object, which creates the connection to and perform
opertions on the MongoDB deployment.
operations on the MongoDB deployment.

You can also use either of these components to customize the way the {+driver-short+} behaves
while connected to MongoDB.
Expand All @@ -40,8 +40,6 @@ Connection URI

A standard connection string includes the following components:

.. Any ref for authentication? Are we planning on making a page for authentication?

.. list-table::
:widths: 20 80
:header-rows: 1
Expand All @@ -58,8 +56,9 @@ A standard connection string includes the following components:

- Optional. Authentication credentials. If you include these, the client
authenticates the user against the database specified in ``authSource``.
For more information about the ``authSource`` connection option, see
:ref:`pymongo-auth`.

.. TODO, add this as last sentence for ``username:password``: For more information about the ``authSource`` connection option, see
:ref:`kotlin-sync-auth`.

* - ``host[:port]``

Expand All @@ -80,23 +79,21 @@ A standard connection string includes the following components:
:ref:`kotlin-sync-connection-options` for a full description of
these options.

.. Is there relevant connection string content for kotlin sync to ref to? Only see for java sync.

For more information about creating a connection string, see
:manual:`Connection Strings </reference/connection-string?tck=docs_driver_kotlin>` in the
MongoDB Server documentation.

Atlas Connection Example
------------------------

To connect to a MongoDB deployment on Atlas, create a client. You can create a
client that uses your connection string and other client options by passing a
To connect to a MongoDB deployment on Atlas, you must first create a client.
You can create a client with your desired configurations by passing a
``MongoClientSettings`` object to the ``MongoClient.create()`` method.

To instantiate a ``MongoClientSettings`` object, use the builder method to
specify your connection string and any other client options, and then call
the ``build()`` method. Chain the ``applyConnectionString()``` method to the
builder to specify your connection URI.
specify your connection string, using the ``applyConnectionString()`` method,
and any other client options. Once you have your desired configuration,
call the ``build()`` method.

You can set the Stable API version client option to avoid breaking changes when
you upgrade to a new server version. To learn more about the Stable API feature,
Expand All @@ -112,99 +109,3 @@ and verify that the connection is successful:
:language: kotlin
:copyable:
:dedent:

Connect to a MongoDB Server or Replica Set
------------------------------------------

If you are connecting to a single MongoDB server instance or a MongoDB
replica set, see the following sections to find out how to connect.

.. _connect-local-kotlin-sync-driver:

Connect to a MongoDB Server on Your Local Machine
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you need to run a MongoDB server on your local machine for development
purposes instead of using an Atlas cluster, you need to complete the following:

1. Download the `Community <https://www.mongodb.com/try/download/community>`__
or `Enterprise <https://www.mongodb.com/try/download/enterprise>`__ version
of MongoDB Server.

#. :ref:`Install and configure <tutorials-installation>`
MongoDB Server.

#. Start the server.

.. important::

Always secure your MongoDB server from malicious attacks. See our
:manual:`Security Checklist </administration/security-checklist/>` for a
list of security recommendations.

After you successfully start your MongoDB server, specify your connection
string in your driver connection code.

If your MongoDB Server is running locally, you can use the connection string
``"mongodb://localhost:<port>"`` where ``<port>`` is the port number you
configured your server to listen for incoming connections. If the port number
is not specified, the default port ``27017`` is used.

If you need to specify a different hostname or IP address, see our Server
Manual entry on :manual:`Connection Strings </reference/connection-string/>`.

.. _connect-replica-set:

Connect to a MongoDB Replica Set
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

A MongoDB replica set deployment is a group of connected instances that
store the same set of data. This configuration of instances provides data
redundancy and high data availability.

To connect to a replica set deployment, specify the hostnames (or IP
addresses) and port numbers of the members of the replica set.

If you are not able to provide a full list of hosts in the replica set,
you can specify a single or subset of the hosts in the replica and
instruct the driver to perform automatic discovery in one of the following
ways:

- Specify the name of the replica set as the value of the ``replicaSet``
parameter
- Specify ``false`` as the value of the ``directConnection`` parameter
- Specify more than one host in the replica set

.. tip::

Although you can specify a subset of the hosts in a replica set,
include all the hosts in the replica set to ensure the driver is able to
establish the connection if one of the hosts are unreachable.

.. _mongo-client-settings-multiple-hosts:

The following examples show how to specify multiple hosts to a ``MongoClient``
instance using either the ``ConnectionString`` or ``MongoClientSettings``
class. Select the tab that corresponds to your preferred class.

.. tabs::

.. tab:: ConnectionString
:tabid: connectionstring

.. literalinclude:: /includes/connect/mongoclient.kt
:start-after: start-replica-set-connection-string
:end-before: end-replica-set-connection-string
:language: kotlin
:copyable:
:dedent:

.. tab:: MongoClientSettings
:tabid: mongoclientsettings

.. literalinclude:: /includes/connect/mongoclient.kt
:start-after: start-replica-set-client-settings
:end-before: end-replica-set-client-settings
:language: kotlin
:copyable:
:dedent:

0 comments on commit ff56653

Please sign in to comment.