Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting a decoder_new_doc fails #12

Open
MarkNijhof opened this issue Mar 20, 2016 · 1 comment
Open

Setting a decoder_new_doc fails #12

MarkNijhof opened this issue Mar 20, 2016 · 1 comment

Comments

@MarkNijhof
Copy link

Hi,

I am using elixir-mongodb which relies on this lib, now by default this returns maps with atom keys, I however would like it to return maps with string keys. So I added the following configuration:

config :bson,
    decoder_new_doc: &Bson.Decoder.elist_to_map/1

In the console I can check that it is loaded correctly:

iex(3)> Application.get_env(:bson, :decoder_new_doc, &Bson.Decoder.elist_to_atom_map/1)
&Bson.Decoder.elist_to_map/1

But when I execute the following I still get atom keys:

iex(4)> [{"a", 1}, {"b", 2}] |> Bson.encode |> Bson.decode
%{a: 1, b: 2}

From looking at the code I should be doing what I am doing, but obviously I am doing something wrong.

@MarkNijhof
Copy link
Author

Forgot, but this works from the console:

iex(6)> [{"a", 1}, {"b", 2}] |> Bson.encode |> Bson.decode(%Bson.Decoder{new_doc: &Bson.Decoder.elist_to_map/1})
%{"a" => 1, "b" => 2}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant