Skip to content

Commit 5334ad0

Browse files
committed
Merge branch 'master' into sessions
2 parents 399e71b + 0db0b0d commit 5334ad0

File tree

7 files changed

+40
-29
lines changed

7 files changed

+40
-29
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 0.5.7
2+
3+
* Bug Fixes
4+
* Test for existing index in `Bucket` works right now
5+
6+
* Enhancements
7+
* Better handling for the `:timeout` options
8+
19
## 0.5.6
210

311
* Bug Fixes

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def application do
7474
end
7575

7676
defp deps do
77-
[{:mongodb_driver, "~> 0.5.3"}]
77+
[{:mongodb_driver, "~> 0.5"}]
7878
end
7979
```
8080

lib/mongo/error.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ defmodule Mongo.Error do
1414

1515
def exception(tag: :tcp, action: action, reason: reason, host: host) do
1616
formatted_reason = :inet.format_error(reason)
17-
%Mongo.Error{message: "#{host} tcp #{action}: #{formatted_reason} - #{inspect(reason)}"}
17+
%Mongo.Error{message: "#{host} tcp #{action}: #{formatted_reason} - #{inspect(reason)}", host: host}
1818
end
1919

2020
def exception(tag: :ssl, action: action, reason: reason, host: host) do
2121
formatted_reason = :ssl.format_error(reason)
22-
%Mongo.Error{message: "#{host} ssl #{action}: #{formatted_reason} - #{inspect(reason)}"}
22+
%Mongo.Error{message: "#{host} ssl #{action}: #{formatted_reason} - #{inspect(reason)}", host: host}
2323
end
2424

2525
def exception(message: message, code: code) do

lib/mongo/grid_fs/bucket.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,13 @@ defmodule Mongo.GridFs.Bucket do
172172
end
173173

174174
# returns true if the collection contains a index with the given name
175-
defp index_member?(topology_pid, coll, index, opts) do
175+
def index_member?(topology_pid, coll, index, opts) do
176176
topology_pid
177177
|> Mongo.list_indexes(coll, opts)
178+
|> Enum.map(fn
179+
%{"name" => name} -> name
180+
_ -> ""
181+
end)
178182
|> Enum.member?(index)
179183
end
180184

lib/mongo/mongo_db_connection.ex

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,29 +256,28 @@ defmodule Mongo.MongoDBConnection do
256256
end
257257
defp execute_action(:command, [cmd], opts, %{wire_version: version} = state) when version >= 6 do
258258

259-
cmd = cmd ++ ["$db": opts[:database] || state.database,
260-
"$readPreference": [mode: update_read_preferences(opts[:slave_ok])]]
261-
262-
timeout = Keyword.get(opts, :max_time, 0)
259+
cmd = cmd ++ ["$db": opts[:database] || state.database, "$readPreference": [mode: update_read_preferences(opts[:slave_ok])]]
263260

264261
# MongoDB 3.6 only allows certain command arguments to be provided this way. These are:
265262
op = case pulling_out?(cmd, :documents) || pulling_out?(cmd, :updates) || pulling_out?(cmd, :deletes) do
266263
nil -> op_msg(flags: 0, sections: [section(payload_type: 0, payload: payload(doc: cmd))])
267264
key -> pulling_out(cmd, key)
268265
end
269266

270-
with {:ok, doc} <- Utils.post_request(op, state.request_id, state, timeout),
267+
# overwrite temporary timeout by timeout option
268+
timeout = Keyword.get(opts, :timeout, state.timeout)
269+
270+
with {:ok, doc} <- Utils.post_request(op, state.request_id, %{state | timeout: timeout}),
271271
state = %{state | request_id: state.request_id + 1} do
272272
{:ok, doc, state}
273273
end
274274
end
275275
defp execute_action(:command, [cmd], opts, state) do
276276

277-
timeout = Keyword.get(opts, :max_time, 0)
278-
flags = Keyword.take(opts, @find_one_flags)
279-
op = op_query(coll: Utils.namespace("$cmd", state, opts[:database]), query: cmd, select: "", num_skip: 0, num_return: 1, flags: flags(flags))
280-
281-
with {:ok, doc} <- Utils.post_request(op, state.request_id, state, timeout),
277+
flags = Keyword.take(opts, @find_one_flags)
278+
op = op_query(coll: Utils.namespace("$cmd", state, opts[:database]), query: cmd, select: "", num_skip: 0, num_return: 1, flags: flags(flags))
279+
timeout = Keyword.get(opts, :timeout, state.timeout)
280+
with {:ok, doc} <- Utils.post_request(op, state.request_id, %{state | timeout: timeout}),
282281
state = %{state | request_id: state.request_id + 1} do
283282
{:ok, doc, state}
284283
end

lib/mongo_db_connection/utils.ex

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ defmodule Mongo.MongoDBConnection.Utils do
1313
Sends a request id and waits for the response with the same id
1414
1515
"""
16-
def post_request(op, id, state, timeout \\ 0) do
16+
def post_request(op, id, state) do
1717

1818
with :ok <- send_data(encode(id, op), state),
19-
{:ok, ^id, response} <- recv_data(nil, "", state, timeout),
19+
{:ok, ^id, response} <- recv_data(nil, "", state),
2020
{:ok, doc} <- get_doc(response),
2121
do: {:ok, doc}
2222
end
@@ -39,7 +39,7 @@ defmodule Mongo.MongoDBConnection.Utils do
3939
command = command ++ ["$db": db]
4040

4141
op_msg(flags: 0, sections: [section(payload_type: 0, payload: payload(doc: command))])
42-
|> post_request(id, state, 0)
42+
|> post_request(id, state)
4343

4444
end
4545
def command(id, command, state) do
@@ -52,7 +52,7 @@ defmodule Mongo.MongoDBConnection.Utils do
5252
end
5353

5454
op_query(coll: ns, query: command, select: "", num_skip: 0, num_return: 1, flags: [])
55-
|> post_request(id, state, 0)
55+
|> post_request(id, state)
5656

5757
end
5858

@@ -84,28 +84,28 @@ defmodule Mongo.MongoDBConnection.Utils do
8484
end
8585
end
8686

87-
defp recv_data(nil, "", %{connection: {mod, socket}} = state, timeout) do
88-
case mod.recv(socket, 0, timeout + state.timeout) do
89-
{:ok, tail} -> recv_data(nil, tail, state, timeout)
87+
defp recv_data(nil, "", %{connection: {mod, socket}} = state) do
88+
case mod.recv(socket, 0, state.timeout) do
89+
{:ok, tail} -> recv_data(nil, tail, state)
9090
{:error, reason} -> recv_error(reason, state)
9191
end
9292
end
93-
defp recv_data(nil, data, %{connection: {mod, socket}} = state, timeout) do
93+
defp recv_data(nil, data, %{connection: {mod, socket}} = state) do
9494
case decode_header(data) do
95-
{:ok, header, rest} -> recv_data(header, rest, state, timeout)
95+
{:ok, header, rest} -> recv_data(header, rest, state)
9696
:error ->
97-
case mod.recv(socket, 0, timeout + state.timeout) do
98-
{:ok, tail} -> recv_data(nil, [data|tail], state, timeout)
97+
case mod.recv(socket, 0, state.timeout) do
98+
{:ok, tail} -> recv_data(nil, [data|tail], state)
9999
{:error, reason} -> recv_error(reason, state)
100100
end
101101
end
102102
end
103-
defp recv_data(header, data, %{connection: {mod, socket}} = state, timeout) do
103+
defp recv_data(header, data, %{connection: {mod, socket}} = state) do
104104
case decode_response(header, data) do
105105
{:ok, id, reply, ""} -> {:ok, id, reply}
106106
:error ->
107-
case mod.recv(socket, 0, timeout + state.timeout) do
108-
{:ok, tail} -> recv_data(header, [data|tail], state, timeout)
107+
case mod.recv(socket, 0, state.timeout) do
108+
{:ok, tail} -> recv_data(header, [data|tail], state)
109109
{:error, reason} -> recv_error(reason, state)
110110
end
111111
end

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Mongodb.Mixfile do
22
use Mix.Project
33

4-
@version "0.5.6"
4+
@version "0.5.7"
55

66
def project() do
77
[app: :mongodb_driver,

0 commit comments

Comments
 (0)