Skip to content

Instantly share code, notes, and snippets.

@skeptomai
Created May 28, 2009 18:16
Show Gist options
  • Save skeptomai/119478 to your computer and use it in GitHub Desktop.
Save skeptomai/119478 to your computer and use it in GitHub Desktop.
remove_field_from_collection(FieldValue, FieldCollectionName, ObjectId) when is_binary(FieldValue) ->
case fetch_document(ObjectId) of
{true, Document} ->
case doc_field(FieldCollectionName, Document) of
undefined -> undefined;
FieldCollection ->
case lists:member(FieldValue, FieldCollection) of
true ->
UpdatedDocument = erlang_couchdb:set_value(FieldCollectionName, lists:delete(FieldValue, DocFiel), Document),
erlang_couchdb:update_document(?OPSCODE_COUCH, ?AUTH_DATABASE, ObjectId, UpdatedDocument);
false ->
undefined
end
end
end.
remove_field_from_collection1(FieldValue, FieldCollectionName, ObjectId) when is_binary(FieldValue) ->
try
{true, Document} = fetch_document(ObjectId),
DocField = doc_field(FieldCollection, Document),
UpdatedDocument = erlang_couchdb:set_value(FieldCollectionName, lists:delete(FieldValue, FieldCollection), Document),
erlang_couchdb:update_document(?OPSCODE_COUCH, ?AUTH_DATABASE, ObjectId, UpdatedDocument)
catch
error:_X -> none
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment