Skip to content

Commit

Permalink
Do not rebuild ObjectId from driver
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmj committed Dec 17, 2015
1 parent 15e6c65 commit b7abfef
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 2 additions & 6 deletions lib/mongo_ecto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,6 @@ defmodule Mongo.Ecto do
def load(_type, nil),
do: {:ok, nil}
# wat
def load(:binary_id, <<_::binary-12>> = binary),
do: {:ok, ObjectID.encode(binary)}
def load(:binary_id, %BSON.ObjectId{value: value}),
do: ObjectID.load(value)
def load(:binary, %BSON.Binary{binary: value}),
Expand All @@ -436,8 +434,6 @@ defmodule Mongo.Ecto do
@doc false
def dump(_type, nil),
do: {:ok, nil}
def dump(:binary_id, <<_::binary-12>> = binary),
do: {:ok, binary}
def dump(:binary_id, data),
do: ObjectID.dump(data)
def dump(:binary, value),
Expand Down Expand Up @@ -521,8 +517,8 @@ defmodule Mongo.Ecto do
normalized = NormalizedQuery.insert(meta, params, pk)

case Connection.insert(repo.__mongo_pool__, normalized, opts) do
{:ok, %{inserted_id: %BSON.ObjectId{value: value}}} ->
{:ok, [{pk, value}]}
{:ok, %{inserted_id: objid}} ->
{:ok, [{pk, objid}]}
other ->
other
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mongo_ecto/conversions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defmodule Mongo.Ecto.Conversions do
do: map(list, &from_ecto_pk(&1, pk))
def from_ecto_pk(value, _pk) when is_literal(value),
do: {:ok, value}
def from_ecto_pk(value, _pk),
def from_ecto_pk(_value, _pk),
do: :error

defp document(doc, pk) do
Expand Down

0 comments on commit b7abfef

Please sign in to comment.