Reputation: 1623
I am trying to use phoenix framework with mongodb as database so i run the following command to get started
mix phoenix.new helloworld --database mongodb
My mix.exs
file looks like this:
defp deps do
[{:phoenix, "~> 1.2.1"},
{:phoenix_pubsub, "~> 1.0"},
{:phoenix_ecto, "~> 3.0"},
{:mongodb_ecto, ">= 0.0.0"},
{:phoenix_html, "~> 2.6"},
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:gettext, "~> 0.11"},
{:cowboy, "~> 1.0"}]
end
but when I run mix deps.get
, I get the following error:
Failed to use "ecto" (versions 2.0.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.0.5, 2.0.6, 2.1.0, 2.1.1, 2.1.2, 2.1.3, 2.1.4) because
mongodb_ecto (versions 0.1.0 to 0.1.2) requires ~> 1.0
phoenix_ecto (version 3.0.1) requires ~> 2.0
Failed to use "ecto" (versions 2.0.0-beta.0 to 2.0.6) because
mongodb_ecto (versions 0.1.0 to 0.1.2) requires ~> 1.0
phoenix_ecto (version 3.0.0) requires ~> 2.0.0-rc
Failed to use "ecto" (version 2.0.6) because
mongodb_ecto (versions 0.1.3 to 0.1.5) requires ~> 1.0.0
phoenix_ecto (version 3.0.0) requires ~> 2.0.0-rc
Failed to use "ecto" (versions 2.1.0 to 2.1.4) because
mongodb_ecto (versions 0.1.0 to 0.1.2) requires ~> 1.0
phoenix_ecto (versions 3.1.0 to 3.2.3) requires ~> 2.1
Failed to use "ecto" (version 2.1.4) because
mongodb_ecto (versions 0.1.3 to 0.1.5) requires ~> 1.0.0
phoenix_ecto (version 3.0.1) requires ~> 2.0
Failed to use "ecto" (version 2.1.4) because
mongodb_ecto (versions 0.1.3 to 0.1.5) requires ~> 1.0.0
phoenix_ecto (versions 3.1.0 to 3.2.3) requires ~> 2.1
** (Mix) Hex dependency resolution failed, relax the version requirements of your dependencies or unlock them (by using mix deps.update or mix deps.unlock). If you are unable to resolve the conflicts you can try overriding with {:dependency, "~> 1.0", override: true}
How do I get started?
Upvotes: 2
Views: 3522
Reputation: 75840
The problem here is that mongodb_ecto
hasn't been updated in quite a while and hence doesn't support the newer versions of Ecto
(v2.0 and above) which is what Phoenix is currently using. This causes mix deps.get
to fail since it cannot resolve the dependencies.
One solution here is to directly use the MongoDB driver for Elixir instead of mongodb_ecto
and configure it to work with Ecto
in your Phoenix application. Here is a blog post that explains how you can do that:
There's also another library that offers MongoDB
support for Ecto 2
, but it's still listed as beta
on the project's github repository. You can check for yourself if it meets your usage criteria:
Upvotes: 6