CouchDB刪除資料庫

CouchDB使用Fauxton刪除資料庫

打開Fauxton網址:http://localhost:5984/_utils/ ,如下圖所示 -

單擊其中一個資料庫:zaixian_db,將看到這個資料庫所有資訊,並點擊刪除(“Delete Database…”)選項來刪除當前資料庫(zaixian_db),如下圖中所示 -

它將顯示一個彈出消息,要求確認資料庫名稱。如下圖中所示 -

點擊“Delete”後,資料庫就被刪除了,列表中再沒有資料庫(zaixian_db)。如下圖中所示 -

CouchDB使用cURL工具刪除資料庫

CouchDB可通過使用cURL實用程式向伺服器發送HTTP請求DELETE方法來刪除資料庫。

語法:

curl -H 'Content-Type: application/json' -X DELETE http://localhost:5984/database_name

注意:HTTP伺服器通信使用-X選項時,用於指定HTTP的自定義請求方法。要刪除資料庫,請通過指定資料庫將URL發送到伺服器。

示例:

要刪除一個名稱為“zaixian_db2”的資料庫。

使用以下命令:

curl -H 'Content-Type: application/json' -X DELETE http://localhost:5984/zaixian_db2

執行結果:

zaixian@ubuntu:~$ curl -H 'Content-Type: application/json' -X DELETE http://localhost:5984/zaixian_db2
{"ok":true}
zaixian@ubuntu:~$

驗證刪除結果

可以使用以下命令驗證資料庫是否被刪除:

zaixian@ubuntu:~$ curl -X GET http://localhost:5984/_all_dbs
["_replicator","_users"]
zaixian@ubuntu:~$

如上面返回的結果集中,資料庫:zaixian_db2已經被刪除了。


上一篇: CouchDB創建資料庫 下一篇: CouchDB快速入門