Skip to content

Commit f498cc7

Browse files
authored
Rewrite mongo.Connect documentation. (#2185)
1 parent bd8b13d commit f498cc7

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

mongo/client.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,19 @@ type Client struct {
8787
authenticator driver.Authenticator
8888
}
8989

90-
// Connect creates a new Client and then initializes it using the Connect method.
90+
// Connect creates a new Client with the given configuration options.
9191
//
92-
// When creating an options.ClientOptions, the order the methods are called matters. Later Set*
93-
// methods will overwrite the values from previous Set* method invocations. This includes the
94-
// ApplyURI method. This allows callers to determine the order of precedence for option
95-
// application. For instance, if ApplyURI is called before SetAuth, the Credential from
96-
// SetAuth will overwrite the values from the connection string. If ApplyURI is called
97-
// after SetAuth, then its values will overwrite those from SetAuth.
92+
// Connect returns an error if the configuration options are invalid, but does
93+
// not validate that the MongoDB deployment is reachable. To verify that the
94+
// deployment is reachable, call [Client.Ping].
9895
//
99-
// The opts parameter is processed using options.MergeClientOptions, which will overwrite entire
100-
// option fields of previous options, there is no partial overwriting. For example, if Username is
101-
// set in the Auth field for the first option, and Password is set for the second but with no
102-
// Username, after the merge the Username field will be empty.
103-
//
104-
// The NewClient function does not do any I/O and returns an error if the given options are invalid.
105-
// The Client.Connect method starts background goroutines to monitor the state of the deployment and does not do
106-
// any I/O in the main goroutine to prevent the main goroutine from blocking. Therefore, it will not error if the
107-
// deployment is down.
108-
//
109-
// The Client.Ping method can be used to verify that the deployment is successfully connected and the
110-
// Client was correctly configured.
96+
// When creating an [options.ClientOptions], the order the methods are called
97+
// matters. Later option setter calls overwrite the values from previous option
98+
// setter calls, including the ApplyURI method. This allows callers to
99+
// determine the order of precedence for setting options. For instance, if
100+
// ApplyURI is called before SetAuth, the Credential from SetAuth will
101+
// overwrite the values from the connection string. If ApplyURI is called
102+
// after SetAuth, then its values will overwrite those from SetAuth.
111103
func Connect(opts ...*options.ClientOptions) (*Client, error) {
112104
c, err := newClient(opts...)
113105
if err != nil {

0 commit comments

Comments
 (0)