Permalink
Browse files

GET now returns the meta json *without* _id and _rev.

  • Loading branch information...
1 parent b3ece62 commit 0765ec0214a6f06267223d454fe556e0044846df @nrdufour nrdufour committed Jul 22, 2012
Showing with 31 additions and 3 deletions.
  1. +28 −0 apps/couch/src/couch_meta.erl
  2. +3 −3 apps/couch_httpd/src/couch_httpd_meta.erl
@@ -19,6 +19,7 @@
-export([create_meta_doc/2]).
-export([delete_meta_doc/1]).
-export([get_meta_doc/1]).
+-export([get_meta/1]).
-export([update_meta_doc/2]).
-export([ensure_meta_db_exists/0]).
@@ -64,6 +65,17 @@ get_meta_doc(DbName) ->
DocId = meta_doc_id(DbName),
couch_db:open_doc(Db, DocId, [ejson_body]).
+%% @doc retrieve the json carrying only the meta information.
+get_meta(DbName) ->
+ case get_meta_doc(DbName) of
+ {ok, Doc} ->
+ Body = Doc#doc.body,
+ MetaValue = remove_couch_props(Body),
+ {ok, MetaValue};
+ Error ->
+ Error
+ end.
+
%% @doc update the meta doc with the given Meta json.
update_meta_doc(DbName, Meta) ->
?LOG_DEBUG("Updating meta for Db ~p with: ~p~n", [DbName, Meta]),
@@ -162,6 +174,22 @@ get_db(DbName) ->
UserCtx = #user_ctx{roles = [<<"_admin">>, DbName]},
couch_db:open_int(DbName, [sys_db, {user_ctx, UserCtx}]).
+remove_couch_props({Body}) ->
+ UpdatedBody = lists:foldl(
+ fun({?COUCH_ID_KEY, _}, Acc) ->
+ % ignore couch id
+ Acc;
+ ({?COUCH_REV_KEY, _}, Acc) ->
+ % ignore couch rev
+ Acc;
+ ({K, _V} = KV, Acc) ->
+ lists:keystore(K, 1, Acc, KV)
+ end,
+ [],
+ Body
+ ),
+ { UpdatedBody }.
+
update_body_with_new_meta({DocBody}, {KVs}) ->
UpdatedBodyArray = lists:foldl(
fun ({?SYSTEM_KEY, _}, Body) ->
@@ -23,9 +23,9 @@
-include_lib("couch_httpd/include/couch_httpd.hrl").
handle_req(#httpd{method='GET', path_parts=[DbName|_]}=Req, _Db) ->
- JsonObj = case couch_meta:get_meta_doc(DbName) of
- {ok, Doc} ->
- couch_doc:to_json_obj(Doc, []);
+ JsonObj = case couch_meta:get_meta(DbName) of
+ {ok, MetaValue} ->
+ MetaValue;
_ ->
null
end,

0 comments on commit 0765ec0

Please sign in to comment.