-
Notifications
You must be signed in to change notification settings - Fork 33
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
base: master
Are you sure you want to change the base?
Changes from all commits
4421603
740235a
48c4785
ad84228
b6f2b9f
b367d65
bd47241
b21283b
e9b98a9
114cff8
e9d6b8d
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 |
---|---|---|
@@ -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 | ||
|
||
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
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. 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. Thanks for calling this out! I can update the name of this section to match the original anchor link. 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'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. 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. 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 | ||
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. [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? 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. 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. 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've reached out to Sahi Muthyala. Let's see what she says 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. 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. We will need an updated screenshot once they update the Atlas UI. 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. 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 | ||
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. Can we switch the "Create a new file" step and the "Add your connection string" step? Currently we have:
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 | ||
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. 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) 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 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? 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. 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 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. You're right. I tested using the 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. 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 | ||
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. One more instance here that should be changed to "MongoDB Go Driver": |
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.
should we add anything about why we're skipping step 2 in the Atlas UI dialog?
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.
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!
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.
Ok, we can keep it as is.