Description
Hi! I'm working on upgrading the Mongo adapter to be compatible with Ecto 3 and #2312 is causing a problem I'm not sure how to fix and I was wondering if you all had any ideas.
Prior to this change, if a field didn't exist in the document retrieved from the database, Ecto would use the default
value. e.g. If the database has this:
%{
_id: 1,
title: "Blog Post",
}
and the schema is:
defmodule App.Post do
schema "posts" do
field(:title, :string),
field(:year, :number, default: 2020)
end
end
And you were to fetch the doc:
doc = App.Repo.get(App.Post, 1)
In Ecto 2.2, Ecto fills in the non-existent field with the default. E.g
doc == %{
_id: 1,
title: "Blog Post",
year: 2020,
}
After this change, Ecto does not fill in the field with the default. In this example, the year is nil
. E.g.
doc == %{
_id: 1,
title: "Blog Post",
year: nil,
}
In our app, we're relying on the default throughout our app and getting a ton of errors as fields we assume to be maps or lists are now nil.
Any idea how we can restore the old functionality with this new model?