You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Kevin Burton <rk...@charter.net> on 2012/11/06 05:00:43 UTC

Clearing a database.

I would like to clear all documents out of the database. What would be a
command that would do that? I can remove an individual document but I am not
sure how to remove all documents.


Re: Clearing a database.

Posted by Keith Gable <zi...@ignition-project.com>.
You have to specify the revision you have to delete though.

DELETE /db/doc?rev=blah

DELETE /db, PUT /db should work


---
Keith Gable
A+ Certified Professional
Network+ Certified Professional
Storage+ Certified Professional
Mobile Application Developer / Web Developer



On Mon, Nov 5, 2012 at 10:22 PM, Dustin Sallings <du...@spy.net> wrote:

> "Kevin Burton" <rk...@charter.net>
> writes:
>
> > Something like
> >
> > curl -X PUT http://127.0.0.1:5984/baseball would create a "baseball"
> > database. Would curl -X DELETE http://127.0.0.1:5984/baseball remove it?
>
>   What did it do when you tried it?  :)
>
> --
> dustin
>
>

Re: Clearing a database.

Posted by Dustin Sallings <du...@spy.net>.
"Kevin Burton" <rk...@charter.net>
writes:

> Something like
>
> curl -X PUT http://127.0.0.1:5984/baseball would create a "baseball"
> database. Would curl -X DELETE http://127.0.0.1:5984/baseball remove it?

  What did it do when you tried it?  :)

-- 
dustin


Re[2]: Clearing a database.

Posted by Yury <fa...@gmail.com>.

Sorry, but the question was "how to clean database" but not delete.
This is very different things. 
For example if I have an integration with ElasticSearch:
- deleting: search engine doesn't delete documents from search index.
- cleaning (remove all documents): removes all documents from search engine

> On Mon, November 5, 2012 23:09, Kevin Burton wrote:
>> Something like
>> curl -X PUT http://127.0.0.1:5984/baseball would create a "baseball"
>> database. Would curl -X DELETE http://127.0.0.1:5984/baseball remove it?
> http://wiki.apache.org/couchdb/HTTP_database_API#DELETE
> CouchDB is pretty well documented (I can assert this as a consumer). Some
> answers to your questions can easily be googled. E.g., search keywords
> "couchdb delete database" (no quotes), click the first link.
> Alex

--
Yury Kisliak
mailto:fas.ysk@gmail.com
skype: fas_tm_an

RE: Clearing a database.

Posted by Alex G <al...@solarapex.com>.
On Mon, November 5, 2012 23:09, Kevin Burton wrote:
> Something like
>
> curl -X PUT http://127.0.0.1:5984/baseball would create a "baseball"
> database. Would curl -X DELETE http://127.0.0.1:5984/baseball remove it?

http://wiki.apache.org/couchdb/HTTP_database_API#DELETE

CouchDB is pretty well documented (I can assert this as a consumer). Some
answers to your questions can easily be googled. E.g., search keywords
"couchdb delete database" (no quotes), click the first link.

Alex


RE: Clearing a database.

Posted by Kevin Burton <rk...@charter.net>.
Something like

curl -X PUT http://127.0.0.1:5984/baseball would create a "baseball"
database. Would curl -X DELETE http://127.0.0.1:5984/baseball remove it?

-----Original Message-----
From: Dustin Sallings [mailto:dustin@spy.net] 
Sent: Monday, November 05, 2012 10:03 PM
To: user@couchdb.apache.org
Subject: Re: Clearing a database.

"Kevin Burton" <rk...@charter.net>
writes:

> I would like to clear all documents out of the database. What would be 
> a command that would do that? I can remove an individual document but 
> I am not sure how to remove all documents.

  Just delete the database.

--
dustin



Re: Clearing a database.

Posted by Dustin Sallings <du...@spy.net>.
"Kevin Burton" <rk...@charter.net>
writes:

> I would like to clear all documents out of the database. What would be a
> command that would do that? I can remove an individual document but I am not
> sure how to remove all documents.

  Just delete the database.

-- 
dustin


Re: Clearing a database.

Posted by Alex G <al...@solarapex.com>.
On Mon, November 5, 2012 23:00, Kevin Burton wrote:
> I would like to clear all documents out of the database. What would be a
> command that would do that? I can remove an individual document but I am
> not
> sure how to remove all documents.

Recreate the database comes first into my mind.

Alex



Re: Clearing a database.

Posted by Simon Metson <si...@cloudant.com>.
Hi, 
You can use _bulk_docs to delete multiple documents at once:

http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API#Modify_Multiple_Documents_With_a_Single_Request

If you can't delete the whole DB I'd write a script that consumes _all_docs?limit=X and deletes all the documents in batches of size X. You can tune X to your setup.
HTH
Simon


On Tuesday, 6 November 2012 at 05:00, Kevin Burton wrote:

> I would like to clear all documents out of the database. What would be a
> command that would do that? I can remove an individual document but I am not
> sure how to remove all documents.




Re: Clearing a database.

Posted by Robert Newson <rn...@apache.org>.
There's no current mechanism to delete all documents without deleting the
database itself and recreating it, however it would be a fairly easy
feature to add; just write a new empty #db_header{}.


On 6 November 2012 08:26, Dave Cottlehuber <dc...@jsonified.com> wrote:

> On 6 November 2012 05:00, Kevin Burton <rk...@charter.net> wrote:
> > I would like to clear all documents out of the database. What would be a
> > command that would do that? I can remove an individual document but I am
> not
> > sure how to remove all documents.
> >
>
> Hi Kevin,
>
> As CouchDB stores versions of every document change (until after
> compaction) what you've asked for is *only* achievable by the CouchDB
> equivalent of "DROP TABLE, CREATE TABLE". You can delete all the
> documents but the db will retain, even after compaction, stubs of the
> old document versions. This cruft is what gives CouchDB its superior
> replication powers, so it's necessary. Without these stubs, the DB has
> no way of comparing doc versions from another DB instance, and knowing
> which are common, and which should be the leaf versions to expose as
> conflicts: http://guide.couchdb.org/draft/conflicts.html
>
> Deleting a DB using the HTTP API, with basic authentication, is as easy as
> :
>
> $ curl -Hcontent-type:application/json -vX PUT
> http://admin:password@localhost:5984/newdb
> * About to connect() to localhost port 5984 (#0)
> *   Trying ::1...
> * Connection refused
> *   Trying 127.0.0.1...
> * connected
> * Connected to localhost (127.0.0.1) port 5984 (#0)
> * Server auth using Basic with user 'admin'
> > PUT /newdb HTTP/1.1
> > Authorization: Basic YWRtaW46cGFzc3dk
> > User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0
> OpenSSL/0.9.8r zlib/1.2.5
> > Host: localhost:5984
> > Accept: */*
> > content-type:application/json
> >
> < HTTP/1.1 201 Created
> < Server: CouchDB/1.3.0a- (Erlang OTP/R15B02)
> < Location: http://localhost:5984/newdb
> < Date: Tue, 06 Nov 2012 08:21:10 GMT
> < Content-Type: text/plain; charset=utf-8
> < Content-Length: 12
> < Cache-Control: must-revalidate
> <
> {"ok":true}
> * Connection #0 to host localhost left intact
> * Closing connection #0
>
>
> $ curl -Hcontent-type:application/json -vX DELETE
> http://admin:password@localhost:5984/newdb
>
> * About to connect() to localhost port 5984 (#0)
> *   Trying ::1...
> * Connection refused
> *   Trying 127.0.0.1...
> * connected
> * Connected to localhost (127.0.0.1) port 5984 (#0)
> * Server auth using Basic with user 'admin'
> > DELETE /newdb HTTP/1.1
> > Authorization: Basic YWRtaW46cGFzc3dk
> > User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0
> OpenSSL/0.9.8r zlib/1.2.5
> > Host: localhost:5984
> > Accept: */*
> > content-type:application/json
> >
> < HTTP/1.1 200 OK
> < Server: CouchDB/1.3.0a- (Erlang OTP/R15B02)
> < Date: Tue, 06 Nov 2012 08:21:18 GMT
> < Content-Type: text/plain; charset=utf-8
> < Content-Length: 12
> < Cache-Control: must-revalidate
> <
> {"ok":true}
>
> * Connection #0 to host localhost left intact
> * Closing connection #0
>
> Possibly a little too easy.
>
> A+
> Dave
>

Re: Clearing a database.

Posted by Dave Cottlehuber <dc...@jsonified.com>.
On 6 November 2012 05:00, Kevin Burton <rk...@charter.net> wrote:
> I would like to clear all documents out of the database. What would be a
> command that would do that? I can remove an individual document but I am not
> sure how to remove all documents.
>

Hi Kevin,

As CouchDB stores versions of every document change (until after
compaction) what you've asked for is *only* achievable by the CouchDB
equivalent of "DROP TABLE, CREATE TABLE". You can delete all the
documents but the db will retain, even after compaction, stubs of the
old document versions. This cruft is what gives CouchDB its superior
replication powers, so it's necessary. Without these stubs, the DB has
no way of comparing doc versions from another DB instance, and knowing
which are common, and which should be the leaf versions to expose as
conflicts: http://guide.couchdb.org/draft/conflicts.html

Deleting a DB using the HTTP API, with basic authentication, is as easy as :

$ curl -Hcontent-type:application/json -vX PUT
http://admin:password@localhost:5984/newdb
* About to connect() to localhost port 5984 (#0)
*   Trying ::1...
* Connection refused
*   Trying 127.0.0.1...
* connected
* Connected to localhost (127.0.0.1) port 5984 (#0)
* Server auth using Basic with user 'admin'
> PUT /newdb HTTP/1.1
> Authorization: Basic YWRtaW46cGFzc3dk
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:5984
> Accept: */*
> content-type:application/json
>
< HTTP/1.1 201 Created
< Server: CouchDB/1.3.0a- (Erlang OTP/R15B02)
< Location: http://localhost:5984/newdb
< Date: Tue, 06 Nov 2012 08:21:10 GMT
< Content-Type: text/plain; charset=utf-8
< Content-Length: 12
< Cache-Control: must-revalidate
<
{"ok":true}
* Connection #0 to host localhost left intact
* Closing connection #0


$ curl -Hcontent-type:application/json -vX DELETE
http://admin:password@localhost:5984/newdb

* About to connect() to localhost port 5984 (#0)
*   Trying ::1...
* Connection refused
*   Trying 127.0.0.1...
* connected
* Connected to localhost (127.0.0.1) port 5984 (#0)
* Server auth using Basic with user 'admin'
> DELETE /newdb HTTP/1.1
> Authorization: Basic YWRtaW46cGFzc3dk
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:5984
> Accept: */*
> content-type:application/json
>
< HTTP/1.1 200 OK
< Server: CouchDB/1.3.0a- (Erlang OTP/R15B02)
< Date: Tue, 06 Nov 2012 08:21:18 GMT
< Content-Type: text/plain; charset=utf-8
< Content-Length: 12
< Cache-Control: must-revalidate
<
{"ok":true}

* Connection #0 to host localhost left intact
* Closing connection #0

Possibly a little too easy.

A+
Dave

Re: Clearing a database.

Posted by Gabriel De Oliveira Barbosa <ma...@gmail.com>.

I have a outdated project related to your question, I don't even know if it works or is useful.

It's basically a Cli to clean database filtering some docs if you want.
If you like the idea make a fork:
https://github.com/manobi/couch-cleaner

Sent from my iPad

On 06/11/2012, at 02:00, "Kevin Burton" <rk...@charter.net> wrote:

> I would like to clear all documents out of the database. What would be a
> command that would do that? I can remove an individual document but I am not
> sure how to remove all documents.
>