Couchdb 简明教程

CouchDB - Deleting a Database

Deleting a Database using cURL Utility

您可以通过使用 DELETE 方法,通过 cURL 实用程序向服务器发送请求来删除 CouchDB 中的数据库。以下是在 CouchDB 中创建数据库的语法:

You can delete a database in CouchDB by sending a request to the server using DELETE method through cURL utility. Following is the syntax to create a database −

$ curl -X DELETE http://127.0.0.1:5984/database name

使用 −X ,我们可以指定在与 HTTP 服务器通信时使用的 HTTP 自定义请求方法。在此情况下,我们使用 DELETE 方法。向服务器发送 url,并在其中指定要删除的数据库。

Using −X we can specify a custom request method of HTTP we are using, while communicating with the HTTP server. In this case, we are using the DELETE method. Send the url to the server by specifying the database to be deleted in it.

Example

假设 CouchDB 中有一个名为 my_database2 的数据库。如果您想使用上述给定的语法删除它,则可以按照以下方式进行:

Assume there is a database named my_database2 in CouchDB. Using the above given syntax if you want to delete it, you can do it as follows −

$ curl -X DELETE http://127.0.0.1:5984/my_database2
{
   "ok" : true
}

作为响应,服务器将返回一个 JSON 文档,其中内容为 “ok”true ,表示操作成功。

As a response, the server will return you a JSON document with content “ok”true indicating the operation was successful.

Verification

通过如下所示列出所有数据库,验证是否已删除数据库。此处您可以观察到已删除数据库 "my_database" 的名称不在列表中。

Verify whether the database is deleted by listing out all the databases as shown below. Here you can observe the name of the deleted database, "my_database" is not there in the list.

$ curl -X GET http://127.0.0.1:5984/_all_dbs

[ "_replicator " , " _users " ]

Deleting a Database using Futon

要删除数据库,请打开 http://127.0.0.1:5984/_utils/ url,您将获得如下所示的 CouchDB 概览/索引页面。

To delete a database, open the http://127.0.0.1:5984/_utils/ url where you will get an Overview/index page of CouchDB as shown below.

delete database1

此处您可以看到三个用户创建的数据库。让我们删除名为 tutorials_point2 的数据库。要删除数据库,请从数据库列表中选择一个,然后单击它,这将转到所选数据库的概览页面,您可以在其中查看数据库的各种操作。以下屏幕截图显示了相同的页面:

Here you can see three user created databases. Let us delete the database named tutorials_point2. To delete a database, select one from the list of databases, and click on it, which will lead to the overview page of the selected database where you can see the various operations on databases. The following screenshot shows the same −

delete database2

在这些选项中,您可以找到 Delete Database 选项。通过单击它,您将获得一个弹出窗口,询问您是否确定!单击删除以删除所选数据库。

Among them you can find Delete Database option. By clicking on it you will get a popup window, asking whether you are sure! Click on delete, to delete the selected database.

delete database3