Skip to content

Commit d02c996

Browse files
lindseymoorestephmarie17mballard-mdbrustagirmcmorisi
authored
DOCSP-47000 Golang comp cov (#13592)
* DOCSP-47019 Shift Go ToC (#499) * DOCSP-47019 Shift Go ToC * generate staging * SA review * connection options drawer * fi crud refs * DOCSP-47018 Authentication Reorg (#502) * DOCSP-47018 Authentication Reorg * edits * edit * add landing page * ref check * landing page refs * fix connect ref * edit * vale get rid of should * 1/2 RR Review * rest of comments * fix toc * ad landing page * edit * DOCSP-49975 Specify Documents to Return (#503) * DOCSP-49975 Specify Documents to Return * edits * fix output * MM review * MM comments * DOCSP-47020 Databases and collections (#504) * DOCSP-49977 Replace One (#506) * DOCSP-49977 Replace One * add to TOC * edit headings * RR review * DOCSP-47023 Connection pools (#505) * DOCSP-49972 removing extra files * DOCSP-49972 Suggestions from review * DOCS-49972 nits * DOCSP-47022 Add link to replication manual (#519) * DOCSP-47006 Retryable Writes and Reads (#518) * DOCSP-49973 Create a MongoClient (#507) * DOCSP-49986: TLS (#520) * DOCSP-49986: TLS * MM small PR fixes * DOCSP-50749: agg tutorial link (#521) * DOCSP-49622 Atlas Search (#508) * DOCSP-49622 Atlas Search * code changes * tech review * rachelm review * fix edit * DOCSP-49976 Update Documents (#517) * DOCSP-49976 Update Documents * edits * retrieve ex fixes * upsert edit * vale edit * headings * input format * revert output * edit code example and RR review * edit * Edit * RR review * DOCSP-49982 Monitor Application Events (#525) * DOCSP-49982 Monitor Application Events * RM comments * DOCSP-50493: quick reference cleanup (#527) * DOCSP-50493: quick reference cleanup * LM PR fixes 1 * DOCSP-49621 Customize cluster settings (#522) * DOCSP-47011: Extended JSON (#528) * DOCSP-47011: Extended JSON * wip * LM PR fixes 1 * QH tech review comment 1 * DOCSP-51236: Remove support for MONGODB-CR auth * Fix * DOCSP-49971: csot cc (#526) * DOCSP-49974 Configure CRUD Operations (#524) * DOCSP-49623 Upgrade versions (#531) * DOCSP-47007 DNS Service Discovery (#533) * DOCSP-47007 DNS Service Discovery * slow build * DOCSP-47012 Document load balancers (#532) * DOCSP-51389 Add Go Specific Pages (#534) * DOCSP-51389 Add Go Specific Pages * add context to index * fix ref on struct tagging * ref in context page * touch ups * Todo and remove usage example mention * add redirects * style * DOCSP-49981 Monitor data with change streams (#535) * DOCSP-49984 Check release note refs (#537) * DOCSP-51826 Check release note refs (cherry picked from commit 89d27e60c900b6b19e84b5ace05fbfb066a74ce2) * remove comment todo * DOCSP-51826 Connection Str as Env Var (#536) * DOCSP-51826 Connection Str as Env Var * edit urls and change section titleto be shorter for url reasons * DOCSP-51826 Check release note refs * Revert "DOCSP-51826 Check release note refs" This reverts commit 89d27e60c900b6b19e84b5ace05fbfb066a74ce2. * DOCSP-51817 Move update usage examples (#540) * DOCSP-51815 Move and standardize find usage exs (#539) * DOCSP-51815 Move and standardize find usage exs * small fixes * fix * MB review * tech feedback * DOCSP-51822 Standardize count usage ex (#542) * DOCSP-51822 Standardize count usage ex * NR review and tech feedback * DOCSP-51818 Standardize replace usage ex (#541) * DOCSP-51818 Standardize replace usage ex * edits * remove str formatting * SA review * tech feedback * monospace * DOCSP-51819 Standardize and move delete usage examples (#544) * DOCSP-52409 Remove struct filter from update usage ex (#550) * DOCSP-51823 Standardize Distinct usage example (#543) * DOCSP-51823 Standardize Distinct usage example * code comment fix * NR review * remaining review * tech feedback * DOCSP-51824 Standardize Run a Command usage ex (#545) * DOCSP-51816 Move and standardize insert usage examples (#538) * DOCSP-51820 Move and standardize bulk operations usage example (#548) * DOCSP-51825 Standardize Struct Tag Usage ex (#546) * v2.1+ client bw link in parallelism note * DOCSP-49699: compound ops page typo fix (#496) * DOCSP-49699: compound ops page typo fix * more fixes I noticed * small fix * small fix * vale * remove screenshots * link description * MW feedback * DOCSP-49853: 2.2.1 release (#498) * DOCSP-50090: Add netlify links action (#500) * DOCSP-50026: remove eol server versions (#501) * DOCSP-50026: remove eol server versions * build * fix * JS feedback * DOCSP-50565: Go v2.2.2 (#510) * DOCSP-49780 Update Go min version (#523) * bson raw * melanie feedback * DOCSP-47019 Shift Go ToC (#499) * DOCSP-47019 Shift Go ToC * generate staging * SA review * connection options drawer * fi crud refs * DOCSP-49976 Update Documents (#517) * DOCSP-49976 Update Documents * edits * retrieve ex fixes * upsert edit * vale edit * headings * input format * revert output * edit code example and RR review * edit * Edit * RR review * review * DOCSP-51814 Add redirects (#13472) * DOCSP-51814 Add redirects * last redirects * last check * formatting fix * NR review remove wildcard recirect chains * DOCSP-49980 Clean up index and toc for Go CC (#13452) * AS review (#13607) --------- Co-authored-by: Stephanie <[email protected]> Co-authored-by: Melanie Ballard <[email protected]> Co-authored-by: Rea Rustagi <[email protected]> Co-authored-by: Michael Morisi <[email protected]> Co-authored-by: rustagir <[email protected]> Co-authored-by: Rachel Mackintosh <[email protected]> Co-authored-by: Nora Reidy <[email protected]> Co-authored-by: Angela <[email protected]> Co-authored-by: Rachel Mackintosh <[email protected]> Co-authored-by: anabellabuckvar <[email protected]>
1 parent 66b539e commit d02c996

File tree

150 files changed

+7567
-5392
lines changed

Some content is hidden

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

150 files changed

+7567
-5392
lines changed

content/golang/current/snooty.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name = "golang"
22
title = "Go Driver"
33
toc_landing_pages = [
4-
"/fundamentals/connections",
5-
"/fundamentals/crud",
6-
"/usage-examples",
4+
"/connect/specify-connection-options",
5+
"/crud/update",
6+
"/security/authentication",
77
]
88

99
intersphinx = [

content/golang/current/source/fundamentals/aggregation.txt renamed to content/golang/current/source/aggregation.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ pipeline consists of one or more **stages**. Each stage performs an
2525
operation based on its expression operators. After the driver executes
2626
the aggregation pipeline, it returns an aggregated result.
2727

28+
.. sharedinclude:: dbx/agg-tutorials-manual-tip.rst
29+
30+
.. replacement:: language
31+
32+
:guilabel:`{+language+}`
33+
2834
Analogy
2935
~~~~~~~
3036

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
.. _golang-atlas-search:
2+
3+
=========================
4+
Run an Atlas Search Query
5+
=========================
6+
7+
.. facet::
8+
:name: genre
9+
:values: reference
10+
11+
.. meta::
12+
:keywords: full text, text analyzer, meta, pipeline, scoring, Lucene
13+
:description: Learn about how to use Atlas Search in the {+driver-long+}.
14+
15+
.. contents:: On this page
16+
:local:
17+
:backlinks: none
18+
:depth: 2
19+
:class: singlecol
20+
21+
Overview
22+
--------
23+
24+
In this guide, you can learn how to use the {+driver-short+} to
25+
run :atlas:`Atlas Search </atlas-search/>` queries on a collection.
26+
Atlas Search enables you to perform full-text searches on collections
27+
hosted on MongoDB Atlas. Atlas Search indexes specify the behavior of the
28+
search and which fields to index.
29+
30+
Sample Data
31+
~~~~~~~~~~~
32+
33+
The example in this guide uses the ``movies`` collection in the ``sample_mflix``
34+
database from the :atlas:`Atlas sample datasets </sample-data>`. To learn how to
35+
create a free MongoDB Atlas cluster and load the sample datasets, see the
36+
:atlas:`Get Started with Atlas </getting-started>` guide.
37+
38+
Run an Atlas Search Query
39+
-------------------------
40+
41+
This section shows how to create an aggregation pipeline to run an
42+
Atlas Search query on a collection.
43+
44+
To run an Atlas Search query, you must create an Atlas Search index on your
45+
collection. To learn how to programmatically create
46+
an Atlas Search index, see the :ref:`golang-atlas-search-indexes` section of the
47+
Indexes guide.
48+
49+
After you create an Atlas Search index, add the ``$search`` stage in your array
50+
of pipeline stages to specify the search criteria. Then, call
51+
the ``Aggregate()`` method and pass your pipeline array as a parameter.
52+
53+
.. tip::
54+
55+
To learn more about aggregation operations, see the :ref:`golang-aggregation`
56+
guide.
57+
58+
Atlas Search Example
59+
~~~~~~~~~~~~~~~~~~~~
60+
61+
This example runs an Atlas Search query by performing the
62+
following actions:
63+
64+
- Creates a ``$search`` stage that instructs the driver
65+
to query for documents in which the ``title`` field contains
66+
the word ``"Alabama"``
67+
68+
- Creates a ``$project`` stage that instructs the driver to
69+
include the ``title`` field in the query results
70+
71+
- Passes the pipeline stages to the ``Aggregate()`` method and
72+
prints the results
73+
74+
.. io-code-block::
75+
:copyable:
76+
77+
.. input:: /includes/fundamentals/code-snippets/indexes/atlasSearch.go
78+
:start-after: begin-atlas-search
79+
:end-before: end-atlas-search
80+
:language: go
81+
:dedent:
82+
83+
.. output::
84+
:language: console
85+
:visible: false
86+
87+
{
88+
_id: new ObjectId('...'),
89+
title: 'Alabama Moon'
90+
}
91+
{
92+
_id: new ObjectId('...'),
93+
title: 'Crazy in Alabama'
94+
}
95+
{
96+
_id: new ObjectId('...'),
97+
title: 'Sweet Home Alabama'
98+
}
99+
100+
Additional Information
101+
----------------------
102+
103+
To learn more about Atlas Search, see the :atlas:`Atlas Search </atlas-search/>`
104+
guides and the :atlas:`$search </atlas-search/aggregation-stages/search/>` pipeline
105+
stage reference in the Atlas documentation.
106+
107+
API Documentation
108+
~~~~~~~~~~~~~~~~~
109+
110+
To learn more about the ``Aggregate()`` method, see the
111+
`API documentation <{+api+}/mongo#Collection.Aggregate>`__.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.. _golang-connection-guide:
2+
.. _golang-connection:
3+
.. _golang-connect:
4+
5+
================
6+
Connection Guide
7+
================
8+
9+
.. facet::
10+
:name: genre
11+
:values: tutorial
12+
13+
.. meta::
14+
:description: Learn how to use the MongoDB Go Driver to connect to MongoDB.
15+
:keywords: connection string, client options, replica set, code example
16+
17+
.. contents:: On this page
18+
:local:
19+
:backlinks: none
20+
:depth: 2
21+
:class: singlecol
22+
23+
.. toctree::
24+
:titlesonly:
25+
:maxdepth: 1
26+
27+
Create a MongoClient </connect/mongoclient>
28+
Choose a Connection Target </connect/connection-targets>
29+
Connection Options </connect/specify-connection-options>
30+
Connection Troubleshooting </connect/connection-troubleshooting>
31+
Connect with AWS Lambda <https://www.mongodb.com/docs/atlas/manage-connections-aws-lambda/>
32+
33+
Overview
34+
--------
35+
36+
Learn how to set up a connection and specify connection behavior from your
37+
application to a MongoDB deployment using the {+driver-short+} in the following
38+
sections:
39+
40+
- :ref:`golang-mongoclient`
41+
- :ref:`golang-connection-options`
42+
- :ref:`golang-connection-troubleshooting`
43+
44+
For more information about authenticating with a MongoDB instance, see the
45+
:ref:`golang-authentication` section.
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
.. _golang-cluster-settings:
2+
3+
==========================
4+
Customize Cluster Settings
5+
==========================
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecol
12+
13+
.. facet::
14+
:name: genre
15+
:values: reference
16+
17+
.. meta::
18+
:keywords: code example, connection string, connection options
19+
20+
Overview
21+
--------
22+
23+
In this guide, you can learn how the {+driver-short+} manages clusters and how
24+
to customize the cluster settings.
25+
26+
Specify Settings
27+
----------------
28+
29+
You can specify settings for your clusters by using either a connection string
30+
or a ``ClientOptions`` struct when creating a new ``Client``
31+
instance. Select the :guilabel:`Connection String` or :guilabel:`ClientOptions` tab to see the
32+
available options.
33+
34+
.. tabs::
35+
36+
.. tab:: Connection String
37+
:tabid: uri
38+
39+
The following table describes the parameters you can use in your connection
40+
string to modify the driver's behavior when interacting with your MongoDB
41+
cluster:
42+
43+
.. list-table::
44+
:header-rows: 1
45+
:stub-columns: 1
46+
:widths: 40 60
47+
48+
* - Parameter
49+
- Description
50+
51+
* - ``serverSelectionTimeoutMS``
52+
- Specifies the maximum amount of time the driver will wait for a server to
53+
be available before throwing an error.
54+
55+
*Default:* 30 seconds
56+
57+
* - ``localThresholdMS``
58+
- Specifies the maximum latency in milliseconds for selecting a server.
59+
60+
*Default:* 15 milliseconds
61+
62+
* - ``replicaSet``
63+
- Specifies the name of the replica set to connect to.
64+
65+
* - ``directConnection``
66+
- Specifies whether to connect directly to a single server, bypassing the
67+
replica set or sharded cluster.
68+
69+
*Default:* ``false``
70+
71+
* - ``loadBalanced``
72+
- Specifies whether the driver is connecting to MongoDB by using a load
73+
balancer. If set to ``true``, the driver assumes that it is
74+
connecting through a load balancer.
75+
76+
You can set this option to ``true`` only if you meet the following requirements:
77+
78+
- You specify only one host name
79+
- You aren't connecting to a replica set
80+
- The ``srvMaxHosts`` option is unset or has a value of ``0``
81+
- The ``directConnection`` option is unset or has a value of ``false``
82+
83+
*Default:* ``false``
84+
85+
* - ``srvServiceName``
86+
- Specifies the service name of the `SRV resource records
87+
<https://www.rfc-editor.org/rfc/rfc2782>`__ the driver retrieves to
88+
construct your :manual:`seed list
89+
</reference/glossary/#std-term-seed-list>`. You must use the
90+
:manual:`DNS Seed List Connection Format
91+
</reference/connection-string/#srv-connection-format>` in
92+
your connection string to use this option.
93+
94+
.. tab:: ClientOptions
95+
:tabid: options
96+
97+
The following table describes several methods you can chain to your
98+
``ClientOptions`` struct to modify the driver's behavior:
99+
100+
.. list-table::
101+
:header-rows: 1
102+
:stub-columns: 1
103+
:widths: 40 60
104+
105+
* - Method
106+
- Description
107+
108+
* - ``SetServerSelectionTimeout()``
109+
- Specifies the maximum amount of time the driver will wait for a server to
110+
be available before throwing an error.
111+
112+
*Default:* 30 seconds
113+
114+
* - ``SetLocalThreshold()``
115+
- Specifies the maximum latency in milliseconds for selecting a server.
116+
117+
*Default:* 15 milliseconds
118+
119+
* - ``SetReplicaSet()``
120+
- Specifies the name of the replica set to connect to.
121+
122+
* - ``SetDirect()``
123+
- Specifies whether to connect directly to a single server, bypassing the
124+
replica set or sharded cluster.
125+
126+
*Default:* ``false``
127+
128+
* - ``SetLoadBalanced()``
129+
- Specifies whether the driver is connecting to MongoDB by using a
130+
load balancer. If set to ``true``, the driver assumes that it is
131+
connecting through a load balancer.
132+
133+
You can set this option to ``true`` only if you meet the following requirements:
134+
135+
- You specify only one host name
136+
- You aren't connecting to a replica set
137+
- The ``srvMaxHosts`` option is unset or has a value of ``0``
138+
- The ``directConnection`` option is unset or has a value of ``false``
139+
140+
*Default:* ``false``
141+
142+
* - ``SetSRVServiceName()``
143+
- Specifies a custom service name of the `SRV resource records
144+
<https://www.rfc-editor.org/rfc/rfc2782>`__ the driver retrieves to
145+
construct your :manual:`seed list
146+
</reference/glossary/#std-term-seed-list>`. To use a custom SRV
147+
service name in SRV discovery, you must call this function before you
148+
call ``ApplyURI()``.
149+
150+
To learn more about the available methods, see the :ref:`golang-cluster-settings-resources` section.
151+
152+
Example
153+
~~~~~~~
154+
155+
Select the :guilabel:`Connection String` or :guilabel:`ClientOptions` tab to
156+
see the corresponding example:
157+
158+
.. tabs::
159+
160+
.. tab:: Connection String
161+
:tabid: uriExample
162+
163+
The following code uses the connection string to configure the maximum
164+
server selection timeout to 10 seconds and the local threshold to 20
165+
milliseconds:
166+
167+
.. literalinclude:: /includes/connect/cluster-settings-uri.go
168+
:language: go
169+
:start-after: start-uri-variable
170+
:end-before: end-uri-variable
171+
:dedent:
172+
173+
The following code creates a client and passes the connection string to the
174+
``ApplyURI()`` method:
175+
176+
.. literalinclude:: /includes/connect/cluster-settings-uri.go
177+
:language: go
178+
:start-after: start-apply-uri
179+
:end-before: end-apply-uri
180+
:dedent:
181+
182+
.. tab:: ClientOptions
183+
:tabid: optionsExample
184+
185+
The following code creates a client and sets the cluster options with a
186+
maximum server selection timeout of 10 seconds and a local threshold of
187+
20 milliseconds:
188+
189+
.. literalinclude:: /includes/connect/cluster-settings-client-options.go
190+
:language: go
191+
:start-after: start-client-options
192+
:end-before: end-client-options
193+
:dedent:
194+
195+
.. _golang-cluster-settings-resources:
196+
197+
API Documentation
198+
-----------------
199+
200+
To learn more about the methods and types in this guide, see the following API documentation:
201+
202+
- `Client <{+api+}/mongo#Client>`__
203+
- `ClientOptions <{+api+}/mongo/options#ClientOptions>`__
204+
- `ApplyURI() <{+api+}/mongo/options#ClientOptions.ApplyURI>`__

0 commit comments

Comments
 (0)