Skip to content

Commit 9fc3fa1

Browse files
External qa (#56)
* autobuilder * testing term role * term doens't work * index improvements * update bson page * linked to README for testing (#45) * update api links to 1.7.2 (#46) * update api links to 1.7.2 * Update source/fundamentals/bson.txt Co-authored-by: kyuan-mongodb <[email protected]> Co-authored-by: kyuan-mongodb <[email protected]> * context page suggestions (#47) * DOCSP-18732 quick start page (#48) * incorporated quickstart feedback * Docsp 18731 (#50) * fix broken links * comment out todo * change link to get uri * update to use godotenv and bson.M * add godotenv to main.go quickstart * nits * text updates for examples * missed click here * DOCSP-18739 (#51) * implemented linking suggestion * DOCSP-18734 connection guide (#52) * updated section headers * Docsp 18736 (#53) * hide link to blank tls guide * list supported mechanisms early * list formatting * autobuilder * DOCSP-18691 (#55) * improved landing page * DOCSP-18738 (#54) * changed _id heading name Co-authored-by: kyuan-mongodb <[email protected]>
1 parent fc85173 commit 9fc3fa1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+512
-292
lines changed

snooty.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ intersphinx = [
1313

1414
[constants]
1515
docs-branch = "master" # always set this to the docs branch (i.e. master, 1.7, 1.8, etc.)
16-
version = "v1.7.0" # always set this to the driver branch (i.e. v1.7.0, v1.8.0, etc.)
16+
version = "v1.7.2" # always set this to the driver branch (i.e. v1.7.0, v1.8.0, etc.)
1717
example = "https://raw.githubusercontent.com/mongodb/docs-golang/{+docs-branch+}/source/includes/usage-examples/code-snippets"
1818
api = "https://pkg.go.dev/go.mongodb.org/mongo-driver@{+version+}"

source/fundamentals.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,12 @@ Fundamentals
2626
/fundamentals/gridfs
2727
/fundamentals/logging
2828
/fundamentals/monitoring
29+
30+
The Fundamentals section explains how to perform the following tasks
31+
using the Go driver:
32+
33+
- :doc:`Connect to MongoDB </fundamentals/connection>`
34+
- :doc:`How the Driver Uses Context </fundamentals/context>`
35+
- :doc:`Authenticate with MongoDB </fundamentals/auth>`
36+
- :doc:`Read from and Write to MongoDB </fundamentals/crud>`
37+
- :doc:`Work with BSON </fundamentals/bson>`

source/fundamentals/auth.txt

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,35 @@ authentication mechanism, see our :doc:`Connection Guide </fundamentals/connecti
2424
Supported Mechanisms
2525
--------------------
2626

27+
The Go driver supports the following authentication mechanisms:
28+
29+
* :ref:`SCRAM-SHA-256 <go_sha_256>`
30+
* :ref:`SCRAM-SHA-1 <go_sha_1>`
31+
* :ref:`MONGODB-CR <go_mongodb_cr>`
32+
* :ref:`MongoDB-AWS <go_mongodb_aws>`
33+
* :ref:`X.509 <go_x509>`
34+
2735
The Go Driver establishes a connection with an authentication mechanism
28-
through a `Client <https://pkg.go.dev/go.mongodb.org/[email protected]/mongo#Client>`__
36+
through a `Client <{+api+}/mongo#Client>`__
2937
type. The ``Client`` type specifies the mechanism and credentials to use
30-
as connection options in a `Credential <https://pkg.go.dev/go.mongodb.org/[email protected]/mongo/options#Credential>`__
38+
as connection options in a `Credential <{+api+}/mongo/options#Credential>`__
3139
type . To configure these options, pass a ``Credential`` type to the
32-
`SetAuth() <https://pkg.go.dev/go.mongodb.org/mongo[email protected]/mongo/options#ClientOptions.SetAuth>`__
33-
function of the `ClientOptions <https://pkg.go.dev/go.mongodb.org/[email protected]/mongo/options#ClientOptions>`__
34-
type.
40+
`SetAuth() <{+api+}/mongo/options#ClientOptions.SetAuth>`__
41+
function of the `ClientOptions <{+api+}/mongo/options#ClientOptions>`__
42+
type.
3543

3644
The following sections demonstrate this process with the five
37-
mechanisms the MongoDB Community Edition supports.
45+
mechanisms the MongoDB Community Edition supports.
3846

3947
Example Conventions
4048
~~~~~~~~~~~~~~~~~~~
4149

42-
Each authentication mechanism contains the following placeholders:
50+
Each authentication mechanism contains the following placeholders:
4351

4452
* ``username`` - Your MongoDB username
4553
* ``password`` - Your MongoDB user's password
4654
* ``hostname`` - Your MongoDB servers network address, accessible by
47-
your client
55+
your client
4856
* ``port`` - Your MongoDB servers port number
4957
* ``authenticationDb`` - Your MongoDB database that contains the user's
5058
authentication data. If you omit this option, the driver uses the
@@ -67,8 +75,8 @@ mechanisms depending on what MongoDB versions your server supports:
6775
- Versions
6876

6977
* - ``SCRAM-SHA-256``
70-
- MongoDB 4.0 and later
71-
78+
- MongoDB 4.0 and later
79+
7280
* - ``SCRAM-SHA-1``
7381
- MongoDB 3.0, 3.2, 3.4, and 3.6
7482

@@ -94,6 +102,8 @@ For more information on the challenge-response (CR) and salted
94102
challenge-response authentication mechanisms (SCRAM) that MongoDB supports,
95103
see the :manual:`SCRAM </core/security-scram/>` section of the server manual.
96104

105+
.. _go_sha_256:
106+
97107
``SCRAM-SHA-256``
98108
~~~~~~~~~~~~~~~~~
99109

@@ -107,7 +117,7 @@ see the :manual:`SCRAM </core/security-scram/>` section of the server manual.
107117
algorithm, to authenticate your user.
108118

109119
To specify the ``SCRAM-SHA-256`` authentication mechanism, assign the
110-
``AuthMechanism`` option the value ``"SCRAM-SHA-256"``:
120+
``AuthMechanism`` option the value ``"SCRAM-SHA-256"``:
111121

112122
.. code-block:: go
113123
:emphasize-lines: 2
@@ -120,10 +130,11 @@ To specify the ``SCRAM-SHA-256`` authentication mechanism, assign the
120130
}
121131
clientOpts := options.Client().ApplyURI("mongodb://<hostname>:<port>").
122132
SetAuth(credential)
123-
133+
124134
client, err := mongo.Connect(context.TODO(), clientOpts)
125135

126136
.. _scram-sha-1-auth-mechanism:
137+
.. _go_sha_1:
127138

128139
``SCRAM-SHA-1``
129140
~~~~~~~~~~~~~~~
@@ -138,7 +149,7 @@ username and password, encrypted with the ``SHA-1`` algorithm, to authenticate
138149
your user.
139150

140151
To specify the ``SCRAM-SHA-1`` authentication mechanism, assign the
141-
``AuthMechanism`` option the value ``"SCRAM-SHA-1"``:
152+
``AuthMechanism`` option the value ``"SCRAM-SHA-1"``:
142153

143154
.. code-block:: go
144155
:emphasize-lines: 2
@@ -154,6 +165,8 @@ To specify the ``SCRAM-SHA-1`` authentication mechanism, assign the
154165

155166
client, err := mongo.Connect(context.TODO(), clientOpts)
156167

168+
.. _go_mongodb_cr:
169+
157170
``MONGODB-CR``
158171
~~~~~~~~~~~~~~
159172

@@ -165,6 +178,8 @@ username and password to authenticate your user.
165178
This authentication mechanism was deprecated starting in MongoDB 3.6
166179
and is no longer supported as of MongoDB 4.0.
167180

181+
.. _go_mongodb_aws:
182+
168183
``MONGODB-AWS``
169184
~~~~~~~~~~~~~~~
170185

@@ -203,7 +218,7 @@ following:
203218
_ = awsIAMClient
204219

205220
If you need to specify an AWS session token, use the temporary
206-
credentials returned from an assume role request.
221+
credentials returned from an assume role request.
207222

208223
To use temporary credentials, assign the ``AuthMechanismProperties``
209224
option the value of your ``sessionToken``:
@@ -224,6 +239,8 @@ option the value of your ``sessionToken``:
224239
assumeRoleClient, err := mongo.Connect(context.TODO(),
225240
options.Client().SetAuth(assumeRoleCredential))
226241

242+
.. _go_x509:
243+
227244
``X.509``
228245
~~~~~~~~~
229246

@@ -258,6 +275,7 @@ following:
258275

259276
clientOpts := options.Client().ApplyURI(uri).SetAuth(credential)
260277

261-
For more information on configuring your application to use
262-
certificates as well as TLS/SSL options, see our
263-
:doc:`TLS/SSL guide </fundamentals/connection/tls>`.
278+
..
279+
For more information on configuring your application to use
280+
certificates as well as TLS/SSL options, see our
281+
:doc:`TLS/SSL guide </fundamentals/connection/tls>`.

source/fundamentals/bson.txt

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
=================
2-
Working with BSON
3-
=================
1+
==============
2+
Work with BSON
3+
==============
44

55
.. default-domain:: mongodb
66

@@ -15,7 +15,7 @@ Overview
1515

1616
In this guide, you can learn about how the Go Driver handles conversions
1717
between BSON and Go values. The process of converting a Go value to
18-
BSON is called **marshalling**, while the reverse process is called **unmarshalling**.
18+
BSON is called **marshalling**, while the reverse process is called **unmarshalling**.
1919

2020
You should read this guide if you want to learn more about how the Go Driver
2121
represents BSON data or need to adjust default marshalling
@@ -39,19 +39,18 @@ The following example demonstrates how to construct a query filter using the
3939
than 100:
4040

4141
.. code-block:: go
42-
42+
4343
filter := bson.D{{"quantity", bson.D{{"$gt", 100}}}}
4444

4545
For more information on how the Go Driver handles BSON data, see the
46-
`bson package API documentation
47-
<https://pkg.go.dev/go.mongodb.org/mongo-driver/bson>`_.
46+
`bson package API documentation <{+api+}/bson>`__.
4847

4948
Struct Tags
5049
-----------
5150

5251
In Go, a **struct** is a collection of data fields with declared data
5352
types. The Go Driver can marshal/unmarshal structs and other native Go
54-
types to/from BSON using a `configurable codec system <https://pkg.go.dev/go.mongodb.org/mongo-driver/bson/bsoncodec>`_.
53+
types to/from BSON using a `configurable codec system <{+api+}/bson/bsoncodec>`_.
5554

5655
You can modify the default marshalling and unmarshalling behavior of the Go Driver using
5756
**struct tags**, which are optional pieces of metadata attached to
@@ -79,11 +78,11 @@ use with the Go Driver:
7978

8079
* - ``truncate``
8180
- If the field type is a non-float numeric type, BSON doubles
82-
unmarshalled into that field will be trucated at the decimal point.
81+
unmarshalled into that field will be truncated at the decimal point.
8382

8483
* - ``inline``
8584
- If the field type is a struct or map field, the field will be
86-
"flattened" when marshalling and "un-flattened" when unmarshalling.
85+
flattened when marshalling and unflattened when unmarshalling.
8786

8887
Without additional instruction from struct tags, the Go
8988
Driver will marshal structs using the following rules:
@@ -101,7 +100,7 @@ Driver will marshal structs using the following rules:
101100
value.
102101

103102
#. When unmarshalling, the Go Driver follows `these D/M type mappings
104-
<https://pkg.go.dev/go.mongodb.org/mongo-driver/bson#hdr-Native_Go_Types>`_
103+
<{+api+}/bson#hdr-Native_Go_Types>`_
105104
for fields of type ``interface{}``. The driver unmarshals BSON documents
106105
unmarshalled into an ``interface{}`` field as a ``D`` type.
107106

@@ -120,7 +119,7 @@ Driver will marshal structs using the following rules:
120119
City string
121120
State string
122121
}
123-
122+
124123
type Student struct {
125124
FirstName string `bson:"first_name,omitempty"`
126125
LastName string `bson:"last_name,omitempty"`
@@ -138,8 +137,8 @@ Driver will marshal structs using the following rules:
138137

139138
.. code-block:: json
140139
:copyable: false
141-
142-
{
140+
141+
{
143142
"_id" : ObjectId("..."),
144143
"first_name" : "Arthur",
145144
"street" : "1 Lakewood Way",
@@ -149,7 +148,7 @@ Driver will marshal structs using the following rules:
149148
}
150149

151150
In this example, struct tags make the driver:
152-
151+
153152
- Set custom BSON field names such as ``first_name``
154153
- Omit the empty ``LastName`` field
155154
- Flatten the nested struct and bring all fields up to the top
@@ -170,7 +169,7 @@ Driver will marshal structs using the following rules:
170169
City string
171170
State string
172171
}
173-
172+
174173
type Student struct {
175174
FirstName string
176175
LastName string
@@ -188,8 +187,8 @@ Driver will marshal structs using the following rules:
188187

189188
.. code-block:: json
190189
:copyable: false
191-
192-
{
190+
191+
{
193192
"_id" : ObjectId("..."),
194193
"firstname" : "Arthur",
195194
"lastname" : "",
@@ -200,9 +199,9 @@ Driver will marshal structs using the following rules:
200199
},
201200
"age" : 8
202201
}
203-
202+
204203
Without struct tags, the driver:
205-
204+
206205
- Sets the lowercase of the struct fields as the BSON field names
207206
- Includes an empty ``lastname`` field
208207
- Stores the ``Address`` field as a nested value
@@ -219,12 +218,12 @@ The ``Decode()`` method returns an ``error`` type which
219218
contains one of the following values:
220219

221220
- ``nil`` if a document matched your query, and there were no errors
222-
retrieving and unmarshalling the document.
221+
retrieving and unmarshalling the document.
223222
- If the driver retrieved your document but could not unmarshal your result, the
224223
``Decode()`` method returns the unmarshalling error.
225224
- If there was an error retrieving your document during execution of the
226225
``FindOne()`` method, the error propagates to the ``Decode()`` method and
227-
the ``Decode()`` method returns the error.
226+
the ``Decode()`` method returns the error.
228227

229228
When used on the ``SingleResult`` type returned by the ``FindOne()``
230229
method, ``Decode()`` can also return the ``ErrNoDocuments`` error if no
@@ -235,7 +234,7 @@ method to unmarshal and read the result of a simple ``FindOne()``
235234
operation:
236235

237236
.. code-block:: go
238-
237+
239238
coll := client.Database("school").Collection("students")
240239
filter := bson.D{{"age", 8}}
241240

@@ -248,21 +247,21 @@ operation:
248247
The output of the preceding code should look like this:
249248

250249
.. code-block:: none
251-
250+
252251
[{_id ObjectID("...")} {first_name Arthur} {street 1 Fern Way} {city Elwood City} {state PA} {age 8}]
253252

254253
The ``Cursor`` type also uses the ``All()`` method, which unmarshals all
255254
documents stored in the cursor into an array at the same time.
256255

257256
The ``bson`` package includes a family of
258257
``Marshal()`` and ``Unmarshal()`` methods that work with BSON-encoded data
259-
of ``[]byte`` type.
258+
of ``[]byte`` type.
260259

261260
The following code demonstrates how you can unmarshal BSON back into a
262261
user-defined struct by using methods from the ``bson`` package:
263262

264263
.. code-block:: go
265-
264+
266265
type Item struct {
267266
Category string
268267
Quantity int32
@@ -279,21 +278,20 @@ user-defined struct by using methods from the ``bson`` package:
279278
The output of the preceding code should look like this:
280279

281280
.. code-block:: none
282-
281+
283282
Unmarshalled Struct:
284283
{Category:plate Quantity:6}
285284

286285
.. note::
287-
286+
288287
You can use the ``Raw`` type to retrieve elements from a BSON
289288
document byte slice without unmarshalling it to a Go value. This can
290289
be useful if you need to look up individual elements without
291290
unmarshalling the entire BSON document.
292291

293292
For more information on the marshalling and unmarshalling methods used with the
294-
``Cursor`` type, see the `Cursor API documentation
295-
<https://pkg.go.dev/go.mongodb.org/[email protected]/mongo#Cursor>`_
293+
``Cursor`` type, see the `Cursor API documentation <{+api+}/mongo#Cursor>`__
296294

297295
For more information on the marshalling and unmarshalling methods in the
298296
``bson`` package, see the `bson API documentation
299-
<https://pkg.go.dev/go.mongodb.org/[email protected]/bson#hdr-Marshalling_and_Unmarshalling>`_
297+
<{+api+}/bson#hdr-Marshalling_and_Unmarshalling>`_

0 commit comments

Comments
 (0)