Hi is there any way to connect mongodb with Ecto with latest version? I really need mongodb as a datastore. thanks in advance
I have gone through couple but this is not working well with latest release
Putting aside my whole dislike towards MongoDB (caused by unfortunate experience of using it’s earl-ish versions), I do not think you can get to work MongoDB as a back-end for Ecto 2.0 just yet. The work is still work in progress, and looks like the guy over here still hasn’t given up hope on making it work with each other: https://github.com/michalmuskala/mongodb_ecto/pull/91
Having said that, there’s nothing from stopping you from using mongo driver directly (2nd link). It’s nice enough I think.
I really doubt that this is true. Postgres can be configured to be very elastic and probably replace all cases where MongoDB can be used - with better result - with exception to keeping open cursors.
It may be as well that you do not need any of the above. You are in Erlang ecosystem in the end. Maybe you should consider some persistence solution like DETS if your data / use case allows that. But I can’t say more since I don’t know our use case
Thanks, I am pretty new to postgres coming from meteor background. was using mongo alot but just found postgress can store jsonp data. i think i will stick with postgress now. thanks
yes, it can, and if you go with UUID for IDs and JSONB as datatype you get more or less the same “feel” as with Mongo with full support from Phoenix. JSONB field just becomes Map in Elixir.
@hubertlepicki Do you happen to know of any good examples of using JSONB?
I’m trying to migrate a Meteor application to phoenix, but there are a couple of areas that use custom fields and I’m struggling to find examples on how to handle them.
So far I have this:
embeds_many :style, App.CustomField
and then
defmodule App.CustomField do
embedded_schema do
field :data, {:array, :map}
end
end
This saves the JSONB correctly, but I’m not sure how to display it in my eex templates? Do I need to use Poison?
I am sorry, I don’t know. I only used it with :map data type. I do not try to use too many ORM features as my relationship with those libs generally “is complicated”.
When you use :map it uses Elixir’s maps that are pretty natural translation from one to another.
Sorry so keep bringing this up, but I’m still not sure I’m using this correctly.
I have an application with 20+ templates called blocks which can all potentially have different styles. They all share a “Block” schema but need a flexible way to add different styles which is why I thought jsonb would be the way to go.
Basically, I want my final template to look something like the pseudo code below but I’m still not sure the best way to save the data and then how to easily access it later?
<style scoped>
p {
color: <%= style.data.color %>
}
h2 {
color: <%= style.data.h2 %>
}
</style>
<section style="background-image: <%= style.data.background-image %>">
<h2>My Heading</h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.</p>
</section>