Skip to content

Commit f4ac8fe

Browse files
committed
update changelog.md, fix unit test
1 parent 30fadee commit f4ac8fe

File tree

7 files changed

+32
-41
lines changed

7 files changed

+32
-41
lines changed

CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## 0.8.5
99
* Enhancements
10-
* Add colored log output
11-
* Add telemetry support for execution
10+
* add colored log output
11+
* add telemetry support for execution
12+
* add new Repo module (thanks to daskycodes)
13+
* add missing typespecs (thanks to fdie)
1214

1315
## 0.8.4 (2022-03-09)
1416
* Bugfix
1517
* add missing excludes from dump function (collections)
1618

1719
## 0.8.3 (2022-02-17)
1820
* Bugfix
19-
* fix no function clause matching (thanks for bodbdigr)
21+
* fix no function clause matching (thanks to bodbdigr)
2022

2123
## 0.8.2 (2022-02-03)
2224
* Enhancements
23-
* Remove a compiler warning (thanks for a-jimenez )
25+
* Remove a compiler warning (thanks to a-jimenez )
2426

2527
## 0.8.1 (2022-01-22)
2628
* Enhancements

lib/mongo.ex

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ defmodule Mongo do
177177
iex> Mongo.uuid("848e90e9-5750-4e0a-ab73-66-c6b328242")
178178
{:error, %ArgumentError{message: "non-alphabet digit found: \"-\" (byte 45)"}}
179179
"""
180-
@spec uuid(any) :: {:ok, BSON.Binary.t()} | {:error, %ArgumentError{}}
180+
@spec uuid(any) :: {:ok, BSON.Binary.t()} | {:error, Exception.t()}
181181
def uuid(string) when is_binary(string) and byte_size(string) == 36 do
182182
try do
183183
p1 = binary_part(string, 0, 8) |> Base.decode16!(case: :lower)
@@ -572,8 +572,7 @@ defmodule Mongo do
572572
end
573573

574574
@doc false
575-
@spec count(GenServer.server(), collection, BSON.document(), Keyword.t()) ::
576-
result(non_neg_integer)
575+
@spec count(GenServer.server(), collection, BSON.document(), Keyword.t()) :: result(non_neg_integer)
577576
def count(topology_pid, coll, filter, opts \\ []) do
578577
cmd =
579578
[
@@ -589,9 +588,7 @@ defmodule Mongo do
589588
opts = Keyword.drop(opts, ~w(limit skip hint collation)a)
590589

591590
with {:ok, doc} <- issue_command(topology_pid, cmd, :read, opts) do
592-
{:ok, trunc(doc["n"])}
593-
else
594-
_ -> {:error, Mongo.Error.exception("Failed to count")}
591+
{:ok, trunc(doc["n"])}
595592
end
596593
end
597594

@@ -623,11 +620,11 @@ defmodule Mongo do
623620
|> Enum.map(&List.wrap/1)
624621

625622
with %Mongo.Stream{} = cursor <- Mongo.aggregate(topology_pid, coll, pipeline, opts),
626-
documents <- Enum.to_list(cursor) do
627-
case documents do
628-
[%{"n" => count}] -> {:ok, count}
629-
[] -> {:ok, 0}
630-
end
623+
documents <- Enum.to_list(cursor) do
624+
case documents do
625+
[%{"n" => count}] -> {:ok, count}
626+
[] -> {:ok, 0}
627+
end
631628
else
632629
_ -> {:error, Mongo.Error.exception("Failed to count")}
633630
end
@@ -1070,19 +1067,18 @@ defmodule Mongo do
10701067
]
10711068
|> filter_nils()
10721069

1073-
with {:ok, doc} <- issue_command(topology_pid, cmd, :write, opts) do
1074-
case doc do
1075-
%{"writeErrors" => _} ->
1076-
{:error, %Mongo.WriteError{n: doc["n"], ok: doc["ok"], write_errors: doc["writeErrors"]}}
1070+
case issue_command(topology_pid, cmd, :write, opts) do
1071+
{:ok, %{"writeErrors" => _} = doc} ->
1072+
{:error, %Mongo.WriteError{n: doc["n"], ok: doc["ok"], write_errors: doc["writeErrors"]}}
10771073

1078-
_ ->
1079-
case acknowledged?(write_concern) do
1080-
false -> {:ok, %Mongo.InsertManyResult{acknowledged: false}}
1081-
true -> {:ok, %Mongo.InsertManyResult{inserted_ids: ids}}
1082-
end
1083-
end
1084-
else
1085-
_ -> {:error, Mongo.Error.exception("Failed to insert many")}
1074+
{:ok, _doc} ->
1075+
case acknowledged?(write_concern) do
1076+
false -> {:ok, %Mongo.InsertManyResult{acknowledged: false}}
1077+
true -> {:ok, %Mongo.InsertManyResult{inserted_ids: ids}}
1078+
end
1079+
1080+
_ ->
1081+
{:error, Mongo.Error.exception("Failed to insert many")}
10861082
end
10871083
end
10881084

@@ -1311,9 +1307,8 @@ defmodule Mongo do
13111307
end
13121308
end
13131309

1314-
13151310
@spec filter_upsert_ids(any) :: list
1316-
defp filter_upsert_ids([_|_] = upserted), do: Enum.map(upserted, fn doc -> doc["_id"] end)
1311+
defp filter_upsert_ids([_ | _] = upserted), do: Enum.map(upserted, fn doc -> doc["_id"] end)
13171312
defp filter_upsert_ids(_), do: []
13181313

13191314
@doc """

lib/mongo/bulk_write.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,7 @@ defmodule Mongo.BulkWrite do
346346
|> BulkWriteResult.reduce()
347347
end
348348

349-
@spec filter_upsert_ids(any) :: list
350-
defp filter_upsert_ids([_|_] = upserted), do: Enum.map(upserted, fn doc -> doc["_id"] end)
349+
defp filter_upsert_ids([_ | _] = upserted), do: Enum.map(upserted, fn doc -> doc["_id"] end)
351350
defp filter_upsert_ids(_), do: []
352351

353352
defp run_commands(session, {cmds, ids}, opts) do

lib/mongo/session.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ defmodule Mongo.Session do
115115
# * `server_session` the server_session data
116116
# * `opts` options
117117
# * `implicit` true or false
118-
# * `causal_consistency` true orfalse
118+
# * `causal_consistency` true or false
119119
# * `wire_version` current wire version to check if transactions are possible
120120
# * `recovery_token` tracked recovery token from response in a sharded transaction
121121
defstruct topology: nil,

lib/mongo/write_concern.ex

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ defmodule Mongo.WriteConcern do
2121
@spec acknowledged?(nil | keyword | map) :: boolean
2222
def acknowledged?(nil), do: true
2323

24-
def acknowledged?(%{} = write_concern), do:
25-
Map.get(write_concern, :w) != 0
24+
def acknowledged?(%{} = write_concern), do: Map.get(write_concern, :w) != 0
2625

27-
def acknowledged?(write_concern) when is_list(write_concern), do:
28-
Keyword.get(write_concern, :w) != 0
26+
def acknowledged?(write_concern) when is_list(write_concern), do: Keyword.get(write_concern, :w) != 0
2927
end

test/mongo/read_preferences_test.exs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ defmodule Mongo.ReadPreferencesTest do
5353
rs.reconfig(conf);
5454
5555
"""
56-
@tag timeout: 700_000
5756
@tag :tag_set
5857
@tag :rs_required
5958
test "find_one, using read_preferences options, tag_set", %{pid: top, catcher: catcher} do
@@ -75,23 +74,21 @@ defmodule Mongo.ReadPreferencesTest do
7574
}
7675

7776
assert %{"name" => "Oskar"} == Mongo.find_one(top, coll, %{name: "Oskar"}, read_preference: prefs) |> Map.take(["name"])
78-
7977
prefs = %{
8078
mode: :nearest,
8179
max_staleness_ms: 120_000,
8280
tag_sets: [dc: "east", usage: "production"]
8381
}
8482

8583
assert %{"name" => "Oskar"} == Mongo.find_one(top, coll, %{name: "Oskar"}, read_preference: prefs) |> Map.take(["name"])
86-
8784
## this configuration results in an empty selection
8885
prefs = %{
8986
mode: :secondary,
9087
max_staleness_ms: 120_000,
9188
tag_sets: [dc: "east", usage: "production"]
9289
}
9390

94-
assert catch_exit(Mongo.find_one(top, coll, %{name: "Oskar"}, read_preference: prefs))
91+
assert catch_exit(Mongo.find_one(top, coll, %{name: "Oskar"}, read_preference: prefs, checkout_timeout: 500))
9592
assert [:checkout_session | _xs] = EventCatcher.empty_selection_events(catcher) |> Enum.map(fn event -> event.action end)
9693
end
9794
end

test/mongo/transaction_retries_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ defmodule Mongo.TransactionRetriesTest do
5151
assert :ok == Session.end_session(top, session)
5252

5353
assert [:commitTransaction, :commitTransaction, :commitTransaction] = EventCatcher.failed_events(catcher) |> Enum.map(fn event -> event.command_name end)
54-
assert [:commitTransaction, :configureFailPoint, :insert, :create] = get_succeeded_events(catcher)
54+
assert [:commitTransaction, :configureFailPoint, :insert, :create] = get_succeeded_events(catcher) |> Enum.reject(fn event -> event == :more_to_come end)
5555
end
5656

5757
@tag :rs_required

0 commit comments

Comments
 (0)