Skip to content

Commit 0d0a3dc

Browse files
committed
bump new version
1 parent 1644467 commit 0d0a3dc

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## 0.6.3
2+
3+
* Enhancements
4+
* basic support for inserting structs
5+
* removed duplicated code
6+
* Cursor-API raises a `Mongo.Error` instead of a `FunctionClauseError`
7+
8+
* Bugfixes
9+
* `:appname` option (typo) #38
10+
* fixed index creation in `Mongo.GridFs.Bucket`
11+
112
## 0.6.2
213

314
* Enhancements

lib/mongo.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,8 +1093,14 @@ defmodule Mongo do
10931093
##
10941094
# Checks the validity of the document structure. that means either you use binaries or atoms as a key, but not in combination of both.
10951095
#
1096-
#
1096+
# todo support for structs
10971097
defp normalize_doc(doc) do
1098+
1099+
#doc = case Map.has_key?(doc, :__struct__) do
1100+
# true -> Map.to_list(doc)
1101+
# false -> doc
1102+
#end
1103+
10981104
Enum.reduce(doc, {:unknown, []}, fn
10991105
{key, _value}, {:binary, _acc} when is_atom(key) -> invalid_doc(doc)
11001106
{key, _value}, {:atom, _acc} when is_binary(key) -> invalid_doc(doc)

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.6.2"
4+
@version "0.6.3"
55

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

test/mongo_test.exs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
defmodule TestUser do
2+
defstruct name: "John", age: 27
3+
end
4+
15
defmodule Mongo.Test do
26
use ExUnit.Case
37

@@ -602,4 +606,19 @@ defmodule Mongo.Test do
602606

603607
end
604608

609+
test "save struct", c do
610+
611+
coll = unique_name()
612+
value = %TestUser{}
613+
{:ok, %Mongo.InsertOneResult{inserted_id: id}} = Mongo.insert_one(c.pid, coll, value)
614+
assert id != nil
615+
616+
user = Mongo.find_one(c.pid, coll, %{_id: id})
617+
|> Enum.into(%{}, fn {key, val} -> {String.to_atom(key), val} end)
618+
619+
user = struct(TestUser, user)
620+
621+
assert value == user
622+
end
623+
605624
end

0 commit comments

Comments
 (0)