@@ -148,15 +148,29 @@ Due to the mongodb specification, an additional connection is always set up for
148
148
149
149
### Replica Sets
150
150
151
- To connect to a Mongo cluster that is using replica sets, it is recommended to use the ` :seeds ` list instead
152
- of a ` :hostname ` and ` :port ` pair.
151
+ By default, the driver will discover the deployment's topology and will connect
152
+ to the replica set automatically, using either the seed list syntax or the URI
153
+ syntax. Assuming the deployment has nodes at ` hostname1.net:27017 ` ,
154
+ ` hostname2.net:27017 ` and ` hostname3.net:27017 ` , either of the following
155
+ invocations will discover the entire deployment:
153
156
154
157
``` elixir
155
- {:ok , pid} = Mongo .start_link (database: " test" , seeds: [" hostname1.net:27017" , " hostname2.net:27017" ])
158
+ {:ok , pid} = Mongo .start_link (database: " test" , seeds: [" hostname1.net:27017" ])
159
+
160
+ {:ok , pid} = Mongo .start_link (url: " mongodb://hostname1.net:27017/test" )
161
+ ```
162
+
163
+ To ensure that the connection succeeds even when some of the nodes are not
164
+ available, it is recommended to list all nodes in both the seed list and the
165
+ URI, as follows:
166
+
167
+ ``` elixir
168
+ {:ok , pid} = Mongo .start_link (database: " test" , seeds: [" hostname1.net:27017" , " hostname2.net:27017" , " hostname3.net:27017" ])
169
+
170
+ {:ok , pid} = Mongo .start_link (url: " mongodb://hostname1.net:27017,hostname2.net:27017,hostname3.net:27017/test" )
156
171
```
157
172
158
- This will allow for scenarios where the first ` "hostname1.net:27017" ` is unreachable for any reason
159
- and will automatically try to connect to each of the following entries in the list to connect to the cluster.
173
+ Using an SRV URI also discovers all nodes of the deployment automatically.
160
174
161
175
### Auth Mechanisms
162
176
0 commit comments