Skip to content
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

DOCSP-43025 Update Quick Start #421

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified source/includes/figures/atlas_connection_copy_string_go.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified source/includes/figures/atlas_connection_select_cluster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 62 additions & 31 deletions source/includes/quick-start/atlas-setup.rst
Original file line number Diff line number Diff line change
@@ -1,49 +1,80 @@
Set up a Free Tier Cluster in Atlas
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

After setting up your Go project dependencies, create a MongoDB cluster
where you can store and manage your data. Complete the
:atlas:`Get Started with Atlas </getting-started>` guide to set up a new
Atlas account, free tier MongoDB cluster, load datasets, and
interact with the data.
You can create a free tier MongoDB deployment on MongoDB Atlas to store and
manage your data. MongoDB Altas hosts and manages your MongoDB database in the
cloud.

After completing the steps in the Atlas guide, you should have a new MongoDB
cluster deployed in Atlas, a new database user, and
:atlas:`sample datasets loaded </sample-data/>` into your cluster.
.. procedure::
:style: connected

.. step:: Create a free tier cluster

Complete the :atlas:`Get Started with Atlas </getting-started>` guide to
set up a new Atlas account, free tier MongoDB cluster, load datasets, and
interact with the data.

.. step:: Save your credentials

After you create your database user, save that user's username and
password to a safe location for use in an upcoming step.

After completing these steps, you have a new MongoDB cluster deployed in
Atlas, a new database user, and :atlas:`sample datasets loaded </sample-data/>`
into your cluster.

.. _golang-connect-to-your-cluster:

Connect to your Cluster
-----------------------
~~~~~~~~~~~~~~~~~~~~~~~

You can connect to your MongoDB deployment by providing a
**connection URI**, also called a *connection string*, which
instructs the driver on how to connect to a MongoDB deployment
and how to behave while connected.

The connection string includes the hostname or IP address and
port of your deployment, the authentication mechanism, user credentials
when applicable, and connection options.

.. procedure::
:style: connected

.. step:: Retrieve your MongoDB Atlas connection string

To retrieve your connection string for the cluster you created in the
previous step, log in to your Atlas account. Navigate to the
:guilabel:`Database` section and click :guilabel:`Clusters`. Click the
:guilabel:`Connect` button for the cluster that you want to connect to as
shown below.

.. figure:: /includes/figures/atlas_connection_select_cluster.png
:alt: Atlas Connection GUI cluster selection screen

In this step, you create and run an application that uses the Go
driver to connect to your MongoDB cluster and run a query on the sample
data.
Then, select the :guilabel:`Drivers` option under the :guilabel:`Connect
to your application` header. Select "Go" from the :guilabel:`Driver`
selection menu and the version that best matches the version you installed
from the :guilabel:`Version` selection menu.

You pass instructions to the driver on where and how to connect to your
MongoDB cluster in a string called the *connection string*. This string
includes information on the hostname or IP address and port of your
cluster, authentication mechanism, user credentials when applicable, and
other connection options.
.. step:: Copy your connection string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add anything about why we're skipping step 2 in the Atlas UI dialog?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think since this screenshot isn't really provided to follow all the steps in the Atlas dialog but just indicating where to copy your connection string, it's ok that they can see the steps. This is the same process for the quick starts for the other drivers. Alternatively, we can crop the screenshot to just show the relevant section (the connection string). Lmk what you think!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we can keep it as is.


To retrieve your connection string for the cluster and user you created in
the previous step, log into your Atlas account and navigate to the
:guilabel:`Database` section and click the :guilabel:`Connect` button for the cluster that you
want to connect to as shown below.
Click the :guilabel:`Copy` button to copy the connection string to your
clipboard, as shown in the following screenshot:

.. figure:: /includes/figures/atlas_connection_select_cluster.png
:alt: Atlas Connection GUI cluster selection screen
.. figure:: /includes/figures/atlas_connection_copy_string_go.png
:alt: Atlas Connection GUI connection string screen

Proceed to the :guilabel:`Connect Your Application` step and select the Go
driver. Then, click the :guilabel:`Copy` button to copy the *connection string*
to your clipboard as shown below.
.. step:: Update the placeholders

.. figure:: /includes/figures/atlas_connection_copy_string_go.png
:alt: Atlas Connection GUI connection string screen
Paste this connection string into a file in your preferred text editor
and replace the ``<db_username>`` and ``<db_password>`` placeholders with
your database user's username and password.

Save this file to a safe location for use in the next step.

Save your Atlas connection string in a safe location that you can access
for the next step.
After completing these steps, you have a connection string that corresponds your
Atlas cluster.

To learn more about connecting to the Go driver through Atlas, see
To learn more about connecting to the {+driver-long+} through Atlas, see
the :atlas:`Atlas driver connection guide </driver-connection>`
and select **Go** from the *Select your language* dropdown.
5 changes: 0 additions & 5 deletions source/includes/quick-start/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ import (
"log"
"os"

"github.com/joho/godotenv"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
)

func main() {
if err := godotenv.Load(); err != nil {
log.Println("No .env file found")
}

uri := os.Getenv("MONGODB_URI")
docs := "www.mongodb.com/docs/drivers/go/current/"
if uri == "" {
Expand Down
4 changes: 2 additions & 2 deletions source/includes/quick-start/overview.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
This guide shows you how to create an application that uses the **Go driver**
This guide shows you how to create an application that uses the **{+driver-long+}**
to connect to a **MongoDB Atlas cluster**. If you prefer to connect to MongoDB
using a different driver or programming language, see our
:driver:`list of official MongoDB drivers <>`.

The Go driver lets you connect to and communicate with MongoDB clusters
The {+driver-long+} lets you connect to and communicate with MongoDB clusters
from a Go application.

MongoDB Atlas is a fully-managed cloud database service that hosts your data
Expand Down
8 changes: 2 additions & 6 deletions source/includes/quick-start/query-output.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
When you run ``main.go``, it should output the details of the movie from
When you run ``main.go``, it outputs the details of the movie from
the sample dataset which looks something like the following:

.. code-block:: json
Expand All @@ -8,8 +8,4 @@ the sample dataset which looks something like the following:
...
"title": "Back to the Future",
...
}

If you receive no output or an error, check whether you properly set up
your environment variable and whether you loaded the sample dataset in
your MongoDB Atlas cluster.
}
105 changes: 54 additions & 51 deletions source/quick-start.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,87 +22,90 @@ Go Driver Quick Start
Set Up Your Project
-------------------

Use Go Mod to Initialize a Project
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. procedure::
:style: connected

Create a new directory and initialize your project by using ``go mod``.
.. step:: Create and initialize your project

.. code-block:: shell
Create a new directory and initialize your project using ``go mod``.

mkdir go-quickstart
cd go-quickstart
go mod init go-quickstart
.. code-block:: shell

.. _golang-add-mongodb-dependency:
mkdir go-quickstart
cd go-quickstart
go mod init go-quickstart

Add MongoDB as a Dependency
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the Atlas UI driver connection links to this anchor (see screenshot), we should ensure this still works.
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for calling this out! I can update the name of this section to match the original anchor link.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm less worried about the exact text, but rather to make sure we have the link set up properly. we're updating the Atlas UI for V2 anyways, so if you give me the correct new link, i can make sure Atlas UI has it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rereading it now, "Add the MongoDB Go Driver as a dependency" probably makes more sense.

~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. step:: Add the {+driver-long+} as a dependency

Use ``go get`` to add the Go driver as a dependency.
Use ``go get`` to add the {+driver-long+} as a dependency.

.. code-block:: shell
.. code-block:: shell

go get go.mongodb.org/mongo-driver/v2/mongo

Add Other Dependencies
~~~~~~~~~~~~~~~~~~~~~~

Use ``go get`` to add any additional dependencies. This Quick Start
uses the ``godotenv`` package to read a MongoDB connection string
from an environment variable to avoid embedding credentials within
source code.

.. code-block:: shell

go get github.com/joho/godotenv
go get go.mongodb.org/mongo-driver/v2/mongo
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note for product reviewer] We have the /v2/ install but the Atlas UI does not use /v2/ yet. Was wondering if there is guidance around if this will be confusing for users to include the screenshot in this case?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very good point. The solution is to update the string in the Atlas UI (in general, there's a bunch of things that still need to be updated to v2). I will file a Jira for this once I figure out the right team.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reached out to Sahi Muthyala. Let's see what she says

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need an updated screenshot once they update the Atlas UI.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, we don't necessarily have to wait for Atlas UI. If it's easier for you, we can merge this once it's ready and then update the screenshot separately. I'll let you choose what you prefer.


Create a MongoDB Cluster
------------------------

.. include:: /includes/quick-start/atlas-setup.rst

Query Your MongoDB Cluster from Your Application
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------------------------------------------------

.. procedure::
:style: connected

.. step:: Create a new file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we switch the "Create a new file" step and the "Add your connection string" step?

Currently we have:

  1. create main.go
  2. export connection string
  3. actually fill out main.go

It would be nice for the creation of main.go and its usage to be together rather than broken up by the "export" command step.


Create a new file called ``main.go`` in the base directory of your project.

.. code-block:: shell

touch main.go

.. step:: Add your connection string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's specify where to paste this connection string (add a step for creating a .env file and move the main.go file creation to the step before the main.go code gets pasted)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current version of this quick start leaves it up to the user if they want to use a .env file or just export their environment variables. Do you think it's better to recommend one path vs the other and add that step?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that this can be done multiple ways. I don't have to strong a preference, but since this is the quick start guide, I would say we should just pick the easiest one. Either way, we should spell it out explicitly, we don't want users getting stuck.

With this in mind, perhaps the easiest thing is just to add it as a variable in the function?

Also, depending on which route we pick, we might not need this import above github.com/joho/godotenv?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I tested using the EXPORT approach without the package and removing the check for the .env file from the quickstart.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good choice. The easier the quick start, the better.


Create an environment variable called ``MONGODB_URI`` and set your
Atlas connection string as its value.

.. code-block:: bash

Next, create a file to contain your application called ``main.go``
in the base directory of your project. Use the following sample
code to run a query on your sample dataset in MongoDB Atlas.
export MONGODB_URI='<your atlas connection string>'

Specify your MongoDB Atlas connection string as the value of the
``uri`` variable, or create an environment variable called
``MONGODB_URI`` and set your Atlas connection string as its value.
.. note::

.. code-block:: bash
Make sure to replace the "<password>" section of the connection string with
the password you created for your user that has **atlasAdmin** permissions.

export MONGODB_URI='<your atlas connection string>'
.. step:: Create your Go application

.. note::
Copy and paste the following code into your ``main.go`` file. This code
runs a query on your sample dataset in MongoDB Atlas.

Make sure to replace the "<password>" section of the connection string with
the password you created for your user that has **atlasAdmin** permissions.
.. literalinclude:: /includes/quick-start/main.go
:language: go
:dedent:

.. literalinclude:: /includes/quick-start/main.go
:language: go
:dedent:
.. step:: Run your application

Run the sample code with the following command from your command line:
Run the sample code with the following command from your command line:

.. code-block:: bash
.. code-block:: bash

go run main.go
go run main.go

.. include:: /includes/quick-start/query-output.rst
.. include:: /includes/quick-start/query-output.rst

.. tip::
.. tip::

If your output is empty, ensure you have loaded the
:atlas:`sample datasets </sample-data/>` into your cluster.
If you receive no output or an error, check whether you properly set up
your environment variable and ensure you have loaded the
:atlas:`sample datasets </sample-data/>` into your cluster.

After completing this step, you should have a working application that uses
the Go driver to connect to your MongoDB cluster, run a query on the
sample data, and print out the result.
After you complete these steps, you have a working application that uses
the {+driver-long+} to connect to your MongoDB cluster, runs a query on the
sample data, and prints out the result.

Next steps
Next Steps
----------

.. include:: /includes/quick-start/next-steps.rst
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more instance here that should be changed to "MongoDB Go Driver":
"Learn how to read and modify data using the Go driver"

Loading