I’m trying to use the phoenix framework and mongodb as the database, so I ran 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?
1> Sheharyar..:
The problem here is that mongodb_ecto
has not been updated for a long time, The new versions (v2.0 and above) currently being used by Ecto
Phoenix are therefore not supported. This causes mix deps.get
to fail because it cannot resolve dependencies .
A solution here is to use Elixir‘s MongoDB driver directly, instead of mongodb_ecto
configuring it as Ecto
Used in a Phoenix application. Here is a blog post explaining how to do this:
Phoenix with Ecto and MongoDB
There is another library Ecto 2
that provides MongoDB
support, but it is still listed as beta
in the project’s github repository. If If it meets your usage standards, you can check it yourself:
eyrmedical/mongo_ecto