Hi (sorry if this got sent twice)

I'm trying to set the database security document ("_security"), from the
Erlang API. I've tried by saving a document with the id "_security" and by
using the *couch_db:set_security* method - both fail and I have no idea why.

1) Saving a document with the id "_security" gives the following error:

{"error":"bad_request","reason":"Only reserved document ids may start with
> underscore."}


2) So I tried using the set_security method:

add_security_doc(Username) ->
> ?LOG_INFO("add_security_doc: ~p", [Username]),
> UsernameBinary = unicode:characters_to_binary(Username),
>
> DbOptions = [{user_ctx, #user_ctx{roles = [<<"_admin">>]}}],
>     {ok, UserDb} = couch_db:open_int(UsernameBinary, DbOptions),
>
> try
> Json = {[
>  {<<"members">>, {[{<<"names">>, []}, {<<"roles">>, UsernameBinary]}]}},
>  {<<"admins">>, {[{<<"names">>, [UsernameBinary]}, {<<"roles">>, []}]}}
> ]},
>
> couch_db:set_security(UserDb, couch_doc:from_json_obj(Json))
> after
> couch_db:close(UserDb)
> end.


But this gives the error:

{"error":"bad_request","reason":""}


Anyone have any idea what I'm doing wrong?

Thanks for your help

Jamie

Reply via email to