Fix `mango_util:load_ddoc/2`
Before this change, `mango_util:load_ddoc/2` would generate a
`function_clause` error. The problem was that `check_lang/1` expects
the document body to be an EJSON object if the document has not been
deleted. However, the document body would be a binary instead, as it is
compressed.
We now make sure that the document body is an EJSON object by adding the
`ejson_body` option when retrieving the document.
diff --git a/src/mango_util.erl b/src/mango_util.erl
index 8e8ccb4..99e15d5 100644
--- a/src/mango_util.erl
+++ b/src/mango_util.erl
@@ -46,8 +46,11 @@
open_doc(Db, DocId) ->
- Opts = [deleted],
- case mango_util:defer(fabric, open_doc, [Db, DocId, Opts]) of
+ open_doc(Db, DocId, [deleted]).
+
+
+open_doc(Db, DocId, Options) ->
+ case mango_util:defer(fabric, open_doc, [Db, DocId, Options]) of
{ok, Doc} ->
{ok, Doc};
{not_found, _} ->
@@ -67,7 +70,7 @@
load_ddoc(Db, DDocId) ->
- case mango_util:open_doc(Db, DDocId) of
+ case open_doc(Db, DDocId, [deleted, ejson_body]) of
{ok, Doc} ->
{ok, check_lang(Doc)};
not_found ->