在CouchDB中,数据库是存储文档的最外层结构。 CouchDB提供cURL实用程序来创建数据库。 您也可以使用Futon
的CouchDB Web界面。
在网络浏览器中打开以下链接:
应该会看到类似下面的一个页面:
点击红色圆圈中的“Create Database”选项卡,创建一个名为“web3_db
”的数据库。
它将显示一条消息,表示数据库已成功创建。可以在概览(Overview)选项卡中检查创建的数据库。
在CouchDB中通过cURL实用程序向服务器发送HTTP请求的PUT方法来创建数据库。
语法:
curl -X PUT http://localhost:5984/database_name |
创建一个名为“web3_db2
”的数据库。服务器将返回一个包含“{ok:true}
”的JSON文档的响应,它表示操作成功。
curl -X PUT http://localhost:5984/web3_db2 |
web3@ubuntu:~$ curl -X PUT http://localhost:5984/web3_db2 |
{"ok":true} |
web3@ubuntu:~$ curl -X PUT http://localhost:5984/web3_db2 |
{"error":"file_exists","reason":"The database could not be created, the file already exists."} |
通过使用以下命令列出所有数据库来验证数据库是否已经创建:
curl -X GET http://localhost:5984/_all_dbs |
示例:
请参阅下面的示例来获取数据库“web3_db2”的信息。
输出:
web3@ubuntu:~$ curl -X GET http://localhost:5984/_all_dbs |
["_replicator","_users","web3_db","web3_db2"] |
web3@ubuntu:~$ |
web3_db
“和”web3_db2
“。