Closed tleyden closed 12 years ago
Not tested.
7: DeleteDocsFun =
fun(DocParam) ->
DocId = couchbeam_doc:get_value("id", DocParam),
io:format("doc id is ~p~n", [DocId]),
Doc = couchbeam_doc:get_value("doc", DocParam),
io:format("the actual document is ~p~n",[Doc]),
DeleteResult = couchbeam:delete_doc(Db, Doc),
io:format("delete result is ~p~n", [DeleteResult]),
DocExists = couchbeam:doc_exists(Db, DocId),
io:format("doc exists ~p~n", [DocExists])
end
-> #Fun
To be able to delete the document form Db you have to pass a JSON as an argument which must have _id and _rev in it. For example {[{<<"_id">>, <<"some id">>}, {<<"_rev">>, <<"the revision number">>}]}. In your example you were passing {[{<<"id">>, <<"some id">>},{<<"key">>, <<"some id">>}, {<<"value">>, {[{<<"rev">>, <<"the revision number">>}]}}, {<<"doc">>, DocJSON}]}. So what we need to do is to get the value of <<"doc">> and pass it as an argument when deleting it from Db.
I hope I make sense ;-)
Cheers
Yes, that makes sense.
I tried this approach and it worked.
DeleteDocsFun = fun(DocWrapper) -> DocId = couchbeam_doc:get_value("id", DocWrapper), io:format("doc id is ~p~n", [DocId]), {ok, DocFetched} = couchbeam:open_doc(Db, DocId), DeleteResult = couchbeam:delete_doc(Db, DocFetched), io:format("delete result is ~p~n", [DeleteResult]), DocExists = couchbeam:doc_exists(Db, DocId), io:format("doc exists ~p~n", [DocExists]) end.
I'm trying to delete all docs with this function, and it doesn't seem to be working. (the docs are still in the db)
Here's the entire shell history with output:
When I look at the db in futon, that doc is still there.
Any ideas on what I'm doing wrong?