John Vaughan
John Vaughan

Reputation: 39

How do you delete all the documents from a Cloudant Database or even Delete the database in Bluemix

I have been working on the Bluemix demo templates and have filled up a Cloudant database with 12k documents. Now I want to start over as this is test data, and want to start with a clean database.

lots of documents

I found I could interactively delete documents 100 at a time, but I need to just start over with a clean database.

Is there a command or menu option for this?

I tried making a new database, which was easy, but i didn't find a way to delete the old one or then rename the new one.

thanks john

Upvotes: 2

Views: 7135

Answers (3)

data_henrik
data_henrik

Reputation: 17118

You could perform a DELETE request to your database:

curl -X DELETE https://username:[email protected]/yourdatabase

The answer indicates whether you succeeded.

As an alternative you can use the Dashboard (GUI). Once you are on the database panel and selected a single database, click the icon for settings and select Delete.

Upvotes: 3

James Thomas
James Thomas

Reputation: 4339

If you want to keep the existing database but remove the documents, you can use CouchDB's Bulk API.

Make a call to the all_docs end point to retrieve the current list of all document identifiers and revision. For each document retrieved, consisting the the _id and _rev fields, add a _deleted field with value true.

Now send a HTTP POST to the _bulk_docs end point for the database, with the updated documents list.

POST /database/_bulk_docs HTTP/1.1

{
    "docs": [
        {
            "_id": "some_document_id",
            "_rev": "1-6a466d5dfda05e613ba97bd737829d67",
            "_deleted": true
        }
        ...
    ]
}

Full details on the Bulk API are here.

Deleted documents will remain in your database until you run the purge command.

Upvotes: 2

ukmadlz
ukmadlz

Reputation: 151

If you want to do this within to dashboard, select the database you want then select the settings cog by the DB name. You'll see a Delete option.

Upvotes: 1

Related Questions