You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by CGS <cg...@gmail.com> on 2011/09/27 07:58:33 UTC
Re: how to delete document with empty _id
There is no document without _id. Predefined (name given at creation by
user) or not (name given by CouchDB), every document has an _id. You
just need to take the _id and you can delete the document (with cURL or
in futon).
On 09/27/2011 02:51 AM, Kwasi Gyasi - Agyei wrote:
> Use couchdb web interface.
>
> http://host:port/_utils
>
> 4Things
> Multimedia and Communication | Property | Entertainment
> Kwasi Owusu Gyasi - Agyei
>
> cell (+27) (0) 76 466 4488
> website www.4things.co.za
> email kwasi.gyasiagyei@4things.co.za
> skype kwasi.gyasiagyei
> role Developer.Designer.Software Architect
>
>
> On 26 Sep 2011, at 9:18 PM, bsquared wrote:
>
>> Hello,
>> I have a document that was created with an empty _id field. I
>> think I did this with an update experiment. How can I access the
>> document to delete it?
>>
>> --
>> Regards,
>> Brian Winfrey
>>
Re: how to delete document with empty _id
Posted by bsquared <bw...@gmail.com>.
Christopher Bonhage <qu...@me.com> writes:
> couchdb -i
>
> DbName = <<"database_name_here">>,
> DocId = <<>>,
> rr(couchdb),
> {ok, Db} = couch_db:open(DbName, [{user_ctx, #user_ctx{roles=[<<"_admin">>]}}]),
> case couch_db:open_doc(Db, DocId) of
> {ok, Doc} ->
> couch_db:update_doc(Db, Doc#doc{deleted=true}, []);
> Error ->
> Error
> end.
>
>
I am looking for a user reference for the erlang shell, but so far none found.
When I run the first command the response appears to be an error report.
[...]
crasher:
initial call: couch_event_sup:init/1
pid: <0.97.0>
registered_name: []
exception exit: {error,{file_error,"/var/log/couchdb/couch.log",eacces}}
in function gen_server:init_it/6
ancestors: [couch_primary_services,couch_server_sup,<0.37.0>]
messages: []
links: [<0.90.0>,<0.6.0>]
dictionary: []
trap_exit: false
status: running
heap_size: 377
stack_size: 24
reductions: 116
neighbours:
[...]
1>
If I run as root I do not get an interactive shell.
--
Regards,
Brian Winfrey
Re: how to delete document with empty _id
Posted by Zachary Zolton <za...@gmail.com>.
Thank you Jason, good to know.
On Fri, Sep 30, 2011 at 11:16 AM, Jason Smith <jh...@iriscouch.com> wrote:
> I do not think Damien's suggestion works. During bulk updates, CouchDB
> will replace both a missing ID and also an empty string ID with a
> UUID.
>
> https://github.com/apache/couchdb/blob/trunk/src/couchdb/couch_httpd_db.erl#L296-299
>
> and
>
> https://github.com/apache/couchdb/blob/trunk/src/couchdb/couch_db.hrl#L99-101
>
> On Fri, Sep 30, 2011 at 10:15 PM, Zachary Zolton
> <za...@gmail.com> wrote:
>> Does the _update function do the same thing as Damien's suggestion to
>> POST to _bulk_docs? (Just curious)
>>
>> On Fri, Sep 30, 2011 at 6:02 AM, Jason Smith <jh...@iriscouch.com> wrote:
>>> You can delete the problematic document with an empty ID using a
>>> Javascript _update function.
>>>
>>> I wrote about it at
>>> http://stackoverflow.com/questions/7604557/how-do-you-delete-a-couchdb-document-with-an-empty-document-id/7605456#7605456
>>>
>>> Basically just make an _update function which returns [{_id:"",
>>> _rev:$your_rev, _deleted:true}, "Hasta lasagna, baby"];
>>>
>>> On Thu, Sep 29, 2011 at 12:50 AM, bsquared <bw...@gmail.com> wrote:
>>>> Christopher Bonhage <qu...@me.com> writes:
>>>>
>>>>> couchdb -i
>>>>>
>>>>> DbName = <<"database_name_here">>,
>>>>> DocId = <<>>,
>>>>> rr(couchdb),
>>>>> {ok, Db} = couch_db:open(DbName, [{user_ctx, #user_ctx{roles=[<<"_admin">>]}}]),
>>>>> case couch_db:open_doc(Db, DocId) of
>>>>> {ok, Doc} ->
>>>>> couch_db:update_doc(Db, Doc#doc{deleted=true}, []);
>>>>> Error ->
>>>>> Error
>>>>> end.
>>>>>
>>>>>
>>>>
>>>> It appears that I need to include a user_ctx record the response from
>>>> this code was:
>>>> * 5: record user_ctx undefined
>>>>
>>>> --
>>>> Regards,
>>>> Brian Winfrey
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Iris Couch
>>>
>>
>
>
>
> --
> Iris Couch
>
Re: how to delete document with empty _id
Posted by Jason Smith <jh...@iriscouch.com>.
I do not think Damien's suggestion works. During bulk updates, CouchDB
will replace both a missing ID and also an empty string ID with a
UUID.
https://github.com/apache/couchdb/blob/trunk/src/couchdb/couch_httpd_db.erl#L296-299
and
https://github.com/apache/couchdb/blob/trunk/src/couchdb/couch_db.hrl#L99-101
On Fri, Sep 30, 2011 at 10:15 PM, Zachary Zolton
<za...@gmail.com> wrote:
> Does the _update function do the same thing as Damien's suggestion to
> POST to _bulk_docs? (Just curious)
>
> On Fri, Sep 30, 2011 at 6:02 AM, Jason Smith <jh...@iriscouch.com> wrote:
>> You can delete the problematic document with an empty ID using a
>> Javascript _update function.
>>
>> I wrote about it at
>> http://stackoverflow.com/questions/7604557/how-do-you-delete-a-couchdb-document-with-an-empty-document-id/7605456#7605456
>>
>> Basically just make an _update function which returns [{_id:"",
>> _rev:$your_rev, _deleted:true}, "Hasta lasagna, baby"];
>>
>> On Thu, Sep 29, 2011 at 12:50 AM, bsquared <bw...@gmail.com> wrote:
>>> Christopher Bonhage <qu...@me.com> writes:
>>>
>>>> couchdb -i
>>>>
>>>> DbName = <<"database_name_here">>,
>>>> DocId = <<>>,
>>>> rr(couchdb),
>>>> {ok, Db} = couch_db:open(DbName, [{user_ctx, #user_ctx{roles=[<<"_admin">>]}}]),
>>>> case couch_db:open_doc(Db, DocId) of
>>>> {ok, Doc} ->
>>>> couch_db:update_doc(Db, Doc#doc{deleted=true}, []);
>>>> Error ->
>>>> Error
>>>> end.
>>>>
>>>>
>>>
>>> It appears that I need to include a user_ctx record the response from
>>> this code was:
>>> * 5: record user_ctx undefined
>>>
>>> --
>>> Regards,
>>> Brian Winfrey
>>>
>>>
>>
>>
>>
>> --
>> Iris Couch
>>
>
--
Iris Couch
Re: how to delete document with empty _id
Posted by Zachary Zolton <za...@gmail.com>.
Does the _update function do the same thing as Damien's suggestion to
POST to _bulk_docs? (Just curious)
On Fri, Sep 30, 2011 at 6:02 AM, Jason Smith <jh...@iriscouch.com> wrote:
> You can delete the problematic document with an empty ID using a
> Javascript _update function.
>
> I wrote about it at
> http://stackoverflow.com/questions/7604557/how-do-you-delete-a-couchdb-document-with-an-empty-document-id/7605456#7605456
>
> Basically just make an _update function which returns [{_id:"",
> _rev:$your_rev, _deleted:true}, "Hasta lasagna, baby"];
>
> On Thu, Sep 29, 2011 at 12:50 AM, bsquared <bw...@gmail.com> wrote:
>> Christopher Bonhage <qu...@me.com> writes:
>>
>>> couchdb -i
>>>
>>> DbName = <<"database_name_here">>,
>>> DocId = <<>>,
>>> rr(couchdb),
>>> {ok, Db} = couch_db:open(DbName, [{user_ctx, #user_ctx{roles=[<<"_admin">>]}}]),
>>> case couch_db:open_doc(Db, DocId) of
>>> {ok, Doc} ->
>>> couch_db:update_doc(Db, Doc#doc{deleted=true}, []);
>>> Error ->
>>> Error
>>> end.
>>>
>>>
>>
>> It appears that I need to include a user_ctx record the response from
>> this code was:
>> * 5: record user_ctx undefined
>>
>> --
>> Regards,
>> Brian Winfrey
>>
>>
>
>
>
> --
> Iris Couch
>
Re: how to delete document with empty _id
Posted by bsquared <bw...@gmail.com>.
Jason Smith <jh...@iriscouch.com> writes:
> You can delete the problematic document with an empty ID using a
> Javascript _update function.
>
> I wrote about it at
> http://stackoverflow.com/questions/7604557/how-do-you-delete-a-couchdb-document-with-an-empty-document-id/7605456#7605456
>
> Basically just make an _update function which returns [{_id:"",
> _rev:$your_rev, _deleted:true}, "Hasta lasagna, baby"];
>
Thank you. That did the trick.
--
Regards,
Brian Winfrey
Re: how to delete document with empty _id
Posted by Jason Smith <jh...@iriscouch.com>.
You can delete the problematic document with an empty ID using a
Javascript _update function.
I wrote about it at
http://stackoverflow.com/questions/7604557/how-do-you-delete-a-couchdb-document-with-an-empty-document-id/7605456#7605456
Basically just make an _update function which returns [{_id:"",
_rev:$your_rev, _deleted:true}, "Hasta lasagna, baby"];
On Thu, Sep 29, 2011 at 12:50 AM, bsquared <bw...@gmail.com> wrote:
> Christopher Bonhage <qu...@me.com> writes:
>
>> couchdb -i
>>
>> DbName = <<"database_name_here">>,
>> DocId = <<>>,
>> rr(couchdb),
>> {ok, Db} = couch_db:open(DbName, [{user_ctx, #user_ctx{roles=[<<"_admin">>]}}]),
>> case couch_db:open_doc(Db, DocId) of
>> {ok, Doc} ->
>> couch_db:update_doc(Db, Doc#doc{deleted=true}, []);
>> Error ->
>> Error
>> end.
>>
>>
>
> It appears that I need to include a user_ctx record the response from
> this code was:
> * 5: record user_ctx undefined
>
> --
> Regards,
> Brian Winfrey
>
>
--
Iris Couch
Re: how to delete document with empty _id
Posted by bsquared <bw...@gmail.com>.
Christopher Bonhage <qu...@me.com> writes:
> couchdb -i
>
> DbName = <<"database_name_here">>,
> DocId = <<>>,
> rr(couchdb),
> {ok, Db} = couch_db:open(DbName, [{user_ctx, #user_ctx{roles=[<<"_admin">>]}}]),
> case couch_db:open_doc(Db, DocId) of
> {ok, Doc} ->
> couch_db:update_doc(Db, Doc#doc{deleted=true}, []);
> Error ->
> Error
> end.
>
>
It appears that I need to include a user_ctx record the response from
this code was:
* 5: record user_ctx undefined
--
Regards,
Brian Winfrey
Re: how to delete document with empty _id
Posted by Christopher Bonhage <qu...@me.com>.
couchdb -i
DbName = <<"database_name_here">>,
DocId = <<>>,
rr(couchdb),
{ok, Db} = couch_db:open(DbName, [{user_ctx, #user_ctx{roles=[<<"_admin">>]}}]),
case couch_db:open_doc(Db, DocId) of
{ok, Doc} ->
couch_db:update_doc(Db, Doc#doc{deleted=true}, []);
Error ->
Error
end.
>> On 09/27/2011 10:00 AM, Alexander Shorin wrote:
>>>
>>> By the way, could hovercraft[1] solve this task? No one have interested?
>>>
>>> [1] https://github.com/jchris/hovercraft
>>>
>>> --
>>>
>>>>> On 09/27/2011 08:50 AM, Mark Hahn wrote:
>>>>>
>>>>>> There is no document without _id.
>>>>>> Not true. I've managed to create a doc with a blank id also. I don't
>>>>>> remember how the bug worked that caused it, but I had to delete the db
>>>>>> to
>>>>>> get rid of it.
>>>>>>
>>>>>>
>>
>>
Re: how to delete document with empty _id
Posted by Alexander Shorin <kx...@gmail.com>.
AFAIK, Couchbeam is HTTP-based CouchDB client, while Hovercraft by
pass HTTP layer and operates with CouchDB directly.
--
,,,^..^,,,
On Tue, Sep 27, 2011 at 12:14 PM, CGS <cg...@gmail.com> wrote:
> Well, I suppose there are many other solutions of this type (e.g.,
> CouchBEAM)...
>
>
> On 09/27/2011 10:00 AM, Alexander Shorin wrote:
>>
>> By the way, could hovercraft[1] solve this task? No one have interested?
>>
>> [1] https://github.com/jchris/hovercraft
>>
>> --
>> ,,,^..^,,,
>>
>>
>> On Tue, Sep 27, 2011 at 11:06 AM, Mark Hahn<ma...@boutiquing.com> wrote:
>>>>
>>>> Nice! Try this: DELETE /db/?rev=x-y
>>>
>>> That would work. It would delete the DB.
>>>
>>> On Mon, Sep 26, 2011 at 11:56 PM, CGS<cg...@gmail.com> wrote:
>>>
>>>> Nice! Try this: DELETE /db/?rev=x-y, where x-y is the revision (never
>>>> tried
>>>> this before :) ). That if you don't want to use futon.
>>>>
>>>>
>>>>
>>>>
>>>> On 09/27/2011 08:50 AM, Mark Hahn wrote:
>>>>
>>>>> There is no document without _id.
>>>>> Not true. I've managed to create a doc with a blank id also. I don't
>>>>> remember how the bug worked that caused it, but I had to delete the db
>>>>> to
>>>>> get rid of it.
>>>>>
>>>>>
>
>
Re: how to delete document with empty _id
Posted by CGS <cg...@gmail.com>.
Well, I suppose there are many other solutions of this type (e.g.,
CouchBEAM)...
On 09/27/2011 10:00 AM, Alexander Shorin wrote:
> By the way, could hovercraft[1] solve this task? No one have interested?
>
> [1] https://github.com/jchris/hovercraft
>
> --
> ,,,^..^,,,
>
>
> On Tue, Sep 27, 2011 at 11:06 AM, Mark Hahn<ma...@boutiquing.com> wrote:
>>> Nice! Try this: DELETE /db/?rev=x-y
>> That would work. It would delete the DB.
>>
>> On Mon, Sep 26, 2011 at 11:56 PM, CGS<cg...@gmail.com> wrote:
>>
>>> Nice! Try this: DELETE /db/?rev=x-y, where x-y is the revision (never tried
>>> this before :) ). That if you don't want to use futon.
>>>
>>>
>>>
>>>
>>> On 09/27/2011 08:50 AM, Mark Hahn wrote:
>>>
>>>> There is no document without _id.
>>>> Not true. I've managed to create a doc with a blank id also. I don't
>>>> remember how the bug worked that caused it, but I had to delete the db to
>>>> get rid of it.
>>>>
>>>>
Re: how to delete document with empty _id
Posted by Alexander Shorin <kx...@gmail.com>.
By the way, could hovercraft[1] solve this task? No one have interested?
[1] https://github.com/jchris/hovercraft
--
,,,^..^,,,
On Tue, Sep 27, 2011 at 11:06 AM, Mark Hahn <ma...@boutiquing.com> wrote:
>> Nice! Try this: DELETE /db/?rev=x-y
>
> That would work. It would delete the DB.
>
> On Mon, Sep 26, 2011 at 11:56 PM, CGS <cg...@gmail.com> wrote:
>
>> Nice! Try this: DELETE /db/?rev=x-y, where x-y is the revision (never tried
>> this before :) ). That if you don't want to use futon.
>>
>>
>>
>>
>> On 09/27/2011 08:50 AM, Mark Hahn wrote:
>>
>>> There is no document without _id.
>>>>
>>> Not true. I've managed to create a doc with a blank id also. I don't
>>> remember how the bug worked that caused it, but I had to delete the db to
>>> get rid of it.
>>>
>>>
>>
>
Re: how to delete document with empty _id
Posted by Mark Hahn <ma...@boutiquing.com>.
> Nice! Try this: DELETE /db/?rev=x-y
That would work. It would delete the DB.
On Mon, Sep 26, 2011 at 11:56 PM, CGS <cg...@gmail.com> wrote:
> Nice! Try this: DELETE /db/?rev=x-y, where x-y is the revision (never tried
> this before :) ). That if you don't want to use futon.
>
>
>
>
> On 09/27/2011 08:50 AM, Mark Hahn wrote:
>
>> There is no document without _id.
>>>
>> Not true. I've managed to create a doc with a blank id also. I don't
>> remember how the bug worked that caused it, but I had to delete the db to
>> get rid of it.
>>
>>
>
Re: how to delete document with empty _id
Posted by bsquared <bw...@gmail.com>.
Thanks for the reply. I tried the code indicated and couchdb returned
an error.
curl -X DELETE
http://localhost:5984/dbname/?rev=1-8ba22720ecb6577f1c7284d43b182643
{"error":"bad_request","reason":"You tried to DELETE a database with a
?=rev parameter. Did you mean to DELETE a document instead?"}
BTW: It is possible to create a document where _id = "" using an upadte
handler.
I no longer have the code, but I set some fields in the doc parameter
and did not set the _id. I called the update handler using curl without
a document path and here is the result:
curl -X GET http://localhost:5984/dbname/_design/backend/_view/vw_invalid
{"total_rows":1,"offset":0,"rows":[
{"id":"","key":"1-8ba22720ecb6577f1c7284d43b182643",
"value":{"_id":"","_rev":"1-8ba22720ecb6577f1c7284d43b182643",
"create_date":"2011-09-24T20:42:51.986Z",
"last_change_date":"2011-09-24T20:42:51.986Z"}}
--
Regards,
Brian Winfrey
Re: how to delete document with empty _id
Posted by CGS <cg...@gmail.com>.
Nice! Try this: DELETE /db/?rev=x-y, where x-y is the revision (never
tried this before :) ). That if you don't want to use futon.
On 09/27/2011 08:50 AM, Mark Hahn wrote:
>> There is no document without _id.
> Not true. I've managed to create a doc with a blank id also. I don't
> remember how the bug worked that caused it, but I had to delete the db to
> get rid of it.
>
Re: how to delete document with empty _id
Posted by Mark Hahn <ma...@boutiquing.com>.
> There is no document without _id.
Not true. I've managed to create a doc with a blank id also. I don't
remember how the bug worked that caused it, but I had to delete the db to
get rid of it.