couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Newson <rnew...@apache.org>
Subject Re: Clearing a database.
Date Tue, 06 Nov 2012 11:12:02 GMT
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 <dch@jsonified.com> wrote:

> On 6 November 2012 05:00, Kevin Burton <rkevinburton@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
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message