Skip to content

Commit 4d6afd8

Browse files
committed
updated documentation
1 parent 37eb9ec commit 4d6afd8

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

README.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ to implement the current requirements for the driver.
2323
* [x] Simplify code: remove raw_find (raw_find called from cursors, raw_find called with "$cmd"), so raw_find is more calling a command than a find query.
2424
* [x] Better support for new MongoDB version, for example the ability to use views
2525
* [x] Upgrade to DBConnection 2.x
26+
* [x] Removed depreacated op codes ([See](https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/#request-opcodes))
2627
* [ ] Because the driver is used in production environments, quick adjustments are necessary.
2728

2829
## Features
2930

3031
* Supports MongoDB versions 3.2, 3.4, 3.6, 4.0
31-
* Connection pooling (through db_connection 2.x)
32+
* Connection pooling (through DBConnection 2.x)
3233
* Streaming cursors
3334
* Performant ObjectID generation
3435
* Follows driver specification set by 10gen
@@ -64,8 +65,7 @@ to implement the current requirements for the driver.
6465

6566
### Installation:
6667

67-
Add mongodb_driver to your mix.exs `deps` and `:applications` (replace `>= 0.0.0` in `deps` if you want a specific version).
68-
The driver supports pooling by db_connection (2.x). If you want to use pooling you should set up your project like this:
68+
Add `mongodb_driver` to your mix.exs `deps` and `:applications`.
6969

7070
```elixir
7171
def application do
@@ -79,11 +79,6 @@ end
7979

8080
Then run `mix deps.get` to fetch dependencies.
8181

82-
### Connection pooling
83-
84-
By default mongodb will start a single connection, but it also supports pooling with the `:pool_size` option.
85-
For 3 connections add the `pool_size: 3` option to `Mongo.start_link` and to all function calls in `Mongo` using the pool.
86-
8782
```elixir
8883
# Starts an unpooled connection
8984
{:ok, conn} = Mongo.start_link(url: "mongodb://localhost:27017/db-name")
@@ -96,6 +91,23 @@ cursor
9691
|> IO.inspect
9792
```
9893

94+
### Connection pooling
95+
The driver supports pooling by DBConnection (2.x). By default `mongodb_driver` will start a single
96+
connection, but it also supports pooling with the `:pool_size` option. For 3 connections add the `pool_size: 3` option to `Mongo.start_link` and to all
97+
function calls in `Mongo` using the pool:
98+
99+
```elixir
100+
# Starts an pooled connection
101+
{:ok, conn} = Mongo.start_link(url: "mongodb://localhost:27017/db-name", pool_size: 3)
102+
103+
# Gets an enumerable cursor for the results
104+
cursor = Mongo.find(conn, "test-collection", %{})
105+
106+
cursor
107+
|> Enum.to_list()
108+
|> IO.inspect
109+
```
110+
99111
If you're using pooling it is recommend to add it to your application supervisor:
100112

101113
```elixir
@@ -111,19 +123,24 @@ def start(_type, _args) do
111123
end
112124
```
113125

126+
Due to the mongodb specification, an additional connection is always set up for the monitor process.
127+
114128
### Replica Sets
115129

116-
To connect to a Mongo cluster that is using replica sets, it is recommended to use the `:seeds` list instead of a `:hostname` and `:port` pair.
130+
To connect to a Mongo cluster that is using replica sets, it is recommended to use the `:seeds` list instead
131+
of a `:hostname` and `:port` pair.
117132

118133
```elixir
119134
{:ok, pid} = Mongo.start_link(database: "test", seeds: ["hostname1.net:27017", "hostname2.net:27017"])
120135
```
121136

122-
This will allow for scenarios where the first `"hostname1.net:27017"` is unreachable for any reason and will automatically try to connect to each of the following entries in the list to connect to the cluster.
137+
This will allow for scenarios where the first `"hostname1.net:27017"` is unreachable for any reason
138+
and will automatically try to connect to each of the following entries in the list to connect to the cluster.
123139

124140
### Auth mechanisms
125141

126-
For versions of Mongo 3.0 and greater, the auth mechanism defaults to SCRAM. If you'd like to use [MONGODB-X509](https://docs.mongodb.com/manual/tutorial/configure-x509-client-authentication/#authenticate-with-a-x-509-certificate)
142+
For versions of Mongo 3.0 and greater, the auth mechanism defaults to SCRAM.
143+
If you'd like to use [MONGODB-X509](https://docs.mongodb.com/manual/tutorial/configure-x509-client-authentication/#authenticate-with-a-x-509-certificate)
127144
authentication, you can specify that as a `start_link` option.
128145

129146
```elixir
@@ -132,7 +149,8 @@ authentication, you can specify that as a `start_link` option.
132149

133150
### AWS, TLS and Erlang SSL ciphers
134151

135-
Some MongoDB cloud providers (notably AWS) require a particular TLS cipher that isn't enabled by default in the Erlang SSL module. In order to connect to these services,
152+
Some MongoDB cloud providers (notably AWS) require a particular TLS cipher that isn't enabled
153+
by default in the Erlang SSL module. In order to connect to these services,
136154
you'll want to add this cipher to your `ssl_opts`:
137155

138156
```elixir

test/mongo/connection_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ defmodule Mongo.ConnectionTest do
3232

3333
defp connect_ssl do
3434
assert {:ok, pid} =
35-
Mongo.start_link(hostname: "localhost", database: "mongodb_test", ssl: true)
35+
Mongo.start_link(hostname: "localhost", database: "mongodb_test", ssl: true, ssl_opts: [ ciphers: ['AES256-GCM-SHA384'], versions: [:"tlsv1.2"] ])
3636
pid
3737
end
3838

0 commit comments

Comments
 (0)