Skip to content

Commit 7ec7b4a

Browse files
authored
Merge pull request #69 from p-mongo/connect-rs
Both seed list and URI discover replica set members by default; updat…
2 parents 56b89fd + c6dfa95 commit 7ec7b4a

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,29 @@ Due to the mongodb specification, an additional connection is always set up for
148148

149149
### Replica Sets
150150

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:
153156

154157
```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")
156171
```
157172

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.
160174

161175
### Auth Mechanisms
162176

0 commit comments

Comments
 (0)