Skip to content

Commit a74b31a

Browse files
committed
Fixes test units, updated readme
1 parent 469d55f commit a74b31a

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

CHANGELOG.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
## v0.5.2
2+
3+
* Enhancements
4+
* Added `op_msg` support ([See](https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/#op-msg))
5+
16
## v0.5.1
27

38
* Enhancements
4-
* upgraded to DBConnection 2.0.6
5-
* refactored code, simplified code and api
6-
* replaced deprecated op_code by database commands
7-
* update_one, update_many, replace_one, replace_many return upserted ids
8-
* support for all find options
9+
* Upgraded to DBConnection 2.0.6
10+
* Refactored code, simplified code and api
11+
* Replaced deprecated op_code by database commands
12+
* Update_one, update_many, replace_one, replace_many return upserted ids
13+
* Support for all find options
914
* Support for MongoDB 3.6 collection [Change Streams](https://docs.mongodb.com/manual/changeStreams/)
1015
* Support for SCRAM-SHA-256 (MongoDB 4.x)
1116

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ to implement the current requirements for the driver.
2525
* [x] Removed depreacated op codes ([See](https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/#request-opcodes))
2626
* [x] Support for SCRAM-SHA-256 (MongoDB 4.x)
2727
* [x] Support for change streaming api ([See](https://github.com/mongodb/specifications/blob/master/source/change-streams/change-streams.rst))
28-
* [ ] Add `op_msg` support ([See](https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/#op-msg))
28+
* [x] Add `op_msg` support ([See](https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/#op-msg))
2929
* [ ] driver sessions ([See](https://github.com/mongodb/specifications/blob/master/source/sessions/driver-sessions.rst))
3030
* [ ] driver transactions ([See](https://github.com/mongodb/specifications/blob/master/source/transactions/transactions.rst))
3131
* [ ] Because the driver is used in production environments, quick adjustments are necessary.

lib/mongo.ex

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ defmodule Mongo do
576576
defp check_for_error(%{"ok" => ok} = response) when ok == 1 do
577577
{:ok, response}
578578
end
579-
defp check_for_error(%{"code" => code, "codeName" => _name, "errmsg" => msg}) do
579+
defp check_for_error(%{"code" => code, "errmsg" => msg}) do
580580
{:error, Mongo.Error.exception(message: msg, code: code)}
581581
end
582582

@@ -945,11 +945,12 @@ defmodule Mongo do
945945
# from the specs
946946
# https://github.com/mongodb/specifications/blob/f4bb783627e7ed5c4095c5554d35287956ef8970/source/enumerate-collections.rst#post-mongodb-280-rc3-versions
947947
#
948-
# In versions 2.8.0-rc3 and later, the listCollections command returns a cursor!
949-
#
950948
cmd = [listCollections: 1]
951949
cursor(topology_pid, cmd, opts)
952-
|> Stream.filter(fn coll -> coll["type"] == "collection" end)
950+
|> Stream.filter(fn
951+
%{"type" => name} -> name == "collection"
952+
_ -> true
953+
end)
953954
|> Stream.map(fn coll -> coll["name"] end)
954955
end
955956

lib/mongo_db_connection/utils.ex

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,9 @@ defmodule Mongo.MongoDBConnection.Utils do
5959

6060
def get_doc(op_reply() = response) do
6161
case response do
62-
op_reply(flags: flags, docs: [%{"$err" => reason, "code" => code}]) when (@reply_query_failure &&& flags) != 0 -> {:error, Mongo.Error.exception(message: reason, code: code)}
63-
op_reply(flags: flags) when (@reply_cursor_not_found &&& flags) != 0 -> {:error, Mongo.Error.exception(message: "cursor not found")}
64-
op_reply(docs: [%{"ok" => 0.0, "errmsg" => reason} = error]) -> {:error, %Mongo.Error{message: "command failed: #{reason}", code: error["code"]}}
65-
op_reply(docs: [%{"ok" => ok} = doc]) when ok == 1 -> {:ok, doc}
66-
op_reply(docs: []) -> {:ok, nil}
62+
op_reply(docs: []) -> {:ok, nil}
63+
op_reply(docs: [doc]) -> {:ok, doc}
64+
op_reply(docs: docs) -> {:ok, docs}
6765
end
6866
end
6967
def get_doc(op_msg(flags: _flags, sections: sections)) do

test/mongo_test.exs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@ defmodule Mongo.Test do
1717

1818
test "command", c do
1919
assert {:ok, %{"ok" => 1.0}} = Mongo.command(c.pid, [ping: true])
20-
assert {:error, %Mongo.Error{}} =
21-
Mongo.command(c.pid, [drop: "unexisting-database"])
20+
assert {:error, %Mongo.Error{}} = Mongo.command(c.pid, [drop: "unexisting-database"])
2221
end
2322

2423
test "command!", c do
2524
assert %{"ok" => 1.0} = Mongo.command!(c.pid, [ping: true])
26-
assert_raise Mongo.Error, fn ->
27-
Mongo.command!(c.pid, [drop: "unexisting-database"])
28-
end
25+
assert_raise Mongo.Error, fn -> Mongo.command!(c.pid, [drop: "unexisting-database"]) end
2926
end
3027

3128
test "show_collections", c do

0 commit comments

Comments
 (0)