elixir-mongo / mongodb

MongoDB driver for Elixir
Apache License 2.0
571 stars 156 forks source link

Custom Mongo.Encoder protocol #341

Closed esse closed 4 years ago

esse commented 4 years ago

Hi,

This PR adds a feature: Mongo.Encoder protocol.

In our project, we very often spot a case when we need to insert map, generated from some struct into the mongo database. With that PR, instead of writing a custom glue code, we can simply implement Mongo.Encoder protocol. Which in turns results in clearer, more idiomatic Elixir code.

deadtrickster commented 4 years ago

I like the idea. How you do decoding back to domain structs?

esse commented 4 years ago

@deadtrickster thanks! Right now, we're decoding them manually - and I believe there is no such elixir idiomatic way of doing that, such as here.

deadtrickster commented 4 years ago

yeah I think it is ecto territory. we should look into it.