Skip to content

Commit c1bdc7b

Browse files
stephmarie17github-actions[bot]
authored andcommitted
DOCSP-43025 Update Quick Start (#421)
(cherry picked from commit 7d909a9)
1 parent 4f85387 commit c1bdc7b

8 files changed

+130
-100
lines changed
39.5 KB
Loading
3.14 KB
Loading

Diff for: source/includes/quick-start/atlas-setup.rst

+64-33
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,80 @@
11
Set up a Free Tier Cluster in Atlas
22
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33

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

10-
After completing the steps in the Atlas guide, you should have a new MongoDB
11-
cluster deployed in Atlas, a new database user, and
12-
:atlas:`sample datasets loaded </sample-data/>` into your cluster.
8+
.. procedure::
9+
:style: connected
10+
11+
.. step:: Create a free tier cluster
12+
13+
Complete the :atlas:`Get Started with Atlas </getting-started>` guide to
14+
set up a new Atlas account, create a free tier MongoDB cluster, load
15+
datasets, and interact with the data.
16+
17+
.. step:: Save your credentials
18+
19+
After you create your database user, save that user's username and
20+
password to a safe location for use in an upcoming step.
21+
22+
After completing these steps, you have a new MongoDB cluster deployed in
23+
Atlas, a new database user, and :atlas:`sample datasets loaded </sample-data/>`
24+
into your cluster.
1325

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

16-
Connect to your Cluster
17-
-----------------------
28+
Connect to Your Cluster
29+
~~~~~~~~~~~~~~~~~~~~~~~
30+
31+
You can connect to your MongoDB deployment by providing a
32+
**connection URI**, also called a *connection string*, which
33+
instructs the driver on how to connect to a MongoDB deployment
34+
and how to behave while connected.
35+
36+
The connection string includes the hostname or IP address and
37+
port of your deployment, the authentication mechanism, user credentials
38+
when applicable, and connection options.
39+
40+
.. procedure::
41+
:style: connected
42+
43+
.. step:: Retrieve your MongoDB Atlas connection string
44+
45+
To retrieve your connection string for the cluster you created in the
46+
previous section, log in to your Atlas account. Navigate to the
47+
:guilabel:`Database` section and click :guilabel:`Clusters`. Click the
48+
:guilabel:`Connect` button for the cluster that you want to connect to as
49+
shown below:
50+
51+
.. figure:: /includes/figures/atlas_connection_select_cluster.png
52+
:alt: Atlas Connection GUI cluster selection screen
1853

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

23-
You pass instructions to the driver on where and how to connect to your
24-
MongoDB cluster in a string called the *connection string*. This string
25-
includes information on the hostname or IP address and port of your
26-
cluster, authentication mechanism, user credentials when applicable, and
27-
other connection options.
59+
.. step:: Copy your connection string
2860

29-
To retrieve your connection string for the cluster and user you created in
30-
the previous step, log into your Atlas account and navigate to the
31-
:guilabel:`Database` section and click the :guilabel:`Connect` button for the cluster that you
32-
want to connect to as shown below.
61+
Click the button to the right of the connection string to copy it to your
62+
clipboard, as shown in the following screenshot:
3363

34-
.. figure:: /includes/figures/atlas_connection_select_cluster.png
35-
:alt: Atlas Connection GUI cluster selection screen
64+
.. figure:: /includes/figures/atlas_connection_copy_string_go.png
65+
:alt: Atlas Connection GUI connection string screen
3666

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

41-
.. figure:: /includes/figures/atlas_connection_copy_string_go.png
42-
:alt: Atlas Connection GUI connection string screen
69+
Paste this connection string into a file in your preferred text editor
70+
and replace the ``<db_username>`` and ``<db_password>`` placeholders with
71+
your database user's username and password.
72+
73+
Save this file to a safe location for use in the next step.
4374

44-
Save your Atlas connection string in a safe location that you can access
45-
for the next step.
75+
After completing these steps, you have a connection string that corresponds your
76+
Atlas cluster.
4677

47-
To learn more about connecting to the Go driver through Atlas, see
78+
To learn more about connecting to the {+driver-long+} through Atlas, see
4879
the :atlas:`Atlas driver connection guide </driver-connection>`
49-
and select **Go** from the *Select your language* dropdown.
80+
and select **Go** from the :guilabel:`Select your language` dropdown.

Diff for: source/includes/quick-start/main.go

-5
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@ import (
77
"log"
88
"os"
99

10-
"github.com/joho/godotenv"
1110
"go.mongodb.org/mongo-driver/v2/bson"
1211
"go.mongodb.org/mongo-driver/v2/mongo"
1312
"go.mongodb.org/mongo-driver/v2/mongo/options"
1413
)
1514

1615
func main() {
17-
if err := godotenv.Load(); err != nil {
18-
log.Println("No .env file found")
19-
}
20-
2116
uri := os.Getenv("MONGODB_URI")
2217
docs := "www.mongodb.com/docs/drivers/go/current/"
2318
if uri == "" {

Diff for: source/includes/quick-start/next-steps.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Learn how to read and modify data using the Go driver in our Fundamentals
2-
CRUD guide or how to perform common operations from our
1+
Learn how to read and modify data using the {+driver-long+} in the
2+
:ref:`golang-crud` section or how to perform common operations from our
33
:ref:`golang-usage-examples`.

Diff for: source/includes/quick-start/overview.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
This guide shows you how to create an application that uses the **Go driver**
1+
This guide shows you how to create an application that uses the **{+driver-long+}**
22
to connect to a **MongoDB Atlas cluster**. If you prefer to connect to MongoDB
33
using a different driver or programming language, see our
44
:driver:`list of official MongoDB drivers <>`.
55

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

99
MongoDB Atlas is a fully-managed cloud database service that hosts your data

Diff for: source/includes/quick-start/query-output.rst

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
When you run ``main.go``, it should output the details of the movie from
2-
the sample dataset which looks something like the following:
1+
When you run ``main.go``, it outputs the details of the movie from
2+
the sample dataset, which resembles the following:
33

44
.. code-block:: json
55
@@ -8,8 +8,4 @@ the sample dataset which looks something like the following:
88
...
99
"title": "Back to the Future",
1010
...
11-
}
12-
13-
If you receive no output or an error, check whether you properly set up
14-
your environment variable and whether you loaded the sample dataset in
15-
your MongoDB Atlas cluster.
11+
}

Diff for: source/quick-start.txt

+59-51
Original file line numberDiff line numberDiff line change
@@ -22,87 +22,95 @@ Go Driver Quick Start
2222
Set Up Your Project
2323
-------------------
2424

25-
Use Go Mod to Initialize a Project
26-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25+
.. procedure::
26+
:style: connected
2727

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

30-
.. code-block:: shell
30+
Create a new directory and initialize your project by using ``go mod``, as
31+
shown in the following commands:
3132

32-
mkdir go-quickstart
33-
cd go-quickstart
34-
go mod init go-quickstart
33+
.. code-block:: shell
3534

36-
.. _golang-add-mongodb-dependency:
35+
mkdir go-quickstart
36+
cd go-quickstart
37+
go mod init go-quickstart
3738

38-
Add MongoDB as a Dependency
39-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
39+
.. step:: Add the {+driver-long+} as a dependency
4040

41-
Use ``go get`` to add the Go driver as a dependency.
41+
Use ``go get`` to add the {+driver-short+} as a dependency, as shown in
42+
the following command:
4243

43-
.. code-block:: shell
44+
.. code-block:: shell
4445

45-
go get go.mongodb.org/mongo-driver/v2/mongo
46-
47-
Add Other Dependencies
48-
~~~~~~~~~~~~~~~~~~~~~~
49-
50-
Use ``go get`` to add any additional dependencies. This Quick Start
51-
uses the ``godotenv`` package to read a MongoDB connection string
52-
from an environment variable to avoid embedding credentials within
53-
source code.
54-
55-
.. code-block:: shell
56-
57-
go get github.com/joho/godotenv
46+
go get go.mongodb.org/mongo-driver/v2/mongo
5847

5948
Create a MongoDB Cluster
6049
------------------------
6150

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

6453
Query Your MongoDB Cluster from Your Application
65-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54+
------------------------------------------------
55+
56+
.. procedure::
57+
:style: connected
58+
59+
.. step:: Add your connection string
60+
61+
In your terminal, run the following command to create an environment
62+
variable called ``MONGODB_URI`` and set your Atlas connection string as
63+
its value:
64+
65+
.. code-block:: bash
66+
67+
export MONGODB_URI='<your atlas connection string>'
68+
69+
.. note::
70+
71+
Make sure to replace the ``<db_password>`` section of the connection
72+
string with the password you created for your user that has
73+
**atlasAdmin** permissions.
74+
75+
.. step:: Create a new file
6676

67-
Next, create a file to contain your application called ``main.go``
68-
in the base directory of your project. Use the following sample
69-
code to run a query on your sample dataset in MongoDB Atlas.
77+
Run the following command from the base directory of your project to
78+
create a new file called ``main.go``:
7079

71-
Specify your MongoDB Atlas connection string as the value of the
72-
``uri`` variable, or create an environment variable called
73-
``MONGODB_URI`` and set your Atlas connection string as its value.
80+
.. code-block:: shell
7481

75-
.. code-block:: bash
82+
touch main.go
7683

77-
export MONGODB_URI='<your atlas connection string>'
84+
.. step:: Create your Go application
7885

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

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

84-
.. literalinclude:: /includes/quick-start/main.go
85-
:language: go
86-
:dedent:
93+
.. step:: Run your application
8794

88-
Run the sample code with the following command from your command line:
95+
Run the sample code with the following command from your command line:
8996

90-
.. code-block:: bash
97+
.. code-block:: bash
9198

92-
go run main.go
99+
go run main.go
93100

94-
.. include:: /includes/quick-start/query-output.rst
101+
.. include:: /includes/quick-start/query-output.rst
95102

96-
.. tip::
103+
.. tip::
97104

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

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

105-
Next steps
113+
Next Steps
106114
----------
107115

108116
.. include:: /includes/quick-start/next-steps.rst

0 commit comments

Comments
 (0)