+ CouchDB entry

I. Introduction
Apache CouchDB database, which is similar to Redis, Cassandra and MongoDB, a NoSQL database also. The CouchDB non-relational data store JSON document. This allows users to CouchDB can with the real world in a similar way to store data.
        Futon called from the command line or a Web interface to manage CouchDB. Futon can be used to perform administrative tasks, such as creating and operating CouchDB databases, documents and users.




Second, address
  https://couchdb.apache.org/#download
CenOS installation: edit  /etc/yum.repos.d/bintray-apache-couchdb-rpm.repo

[AppleScript]  plain text view  Copy the code
?
1
2
3
4
5
6
[bintray--apache-couchdb-rpm]
name=bintray--apache-couchdb-rpm
baseurl=http://apache.bintray.com/couchdb-rpm/el$releasever/$basearch/
gpgcheck=0
repo_gpgcheck=0
enabled=1


Then install   yum -y install EPEL-Release  &&  sudo yum -y install CouchDB
Third, access management
after the start, you can page through a browser to access http: // localhost: to validate 5984 / _utils / index.html installation was successful, you can this page management CouchDB.
Or verified by the command line curl

[AppleScript]  plain text view  Copy the code
?
1
2
$ curl http://localhost:5984
{"couchdb":"Welcome","version":"2.3.1","git_sha":"c298091a4","uuid":"04de5436d56ab4a1a4ace6c16555fbe4","features":["pluggable-storage-engines","scheduler"],"vendor":{"name":"The Apache Software Foundation"}}


The default CouchDB can only be accessed by the machine can be achieved by modifying bind_address vim /opt/couchdb/etc/default.ini configuration file, then restart CouchDB.

[AppleScript]  plain text view  Copy the code
?
1
2
3
4
bind_address = 127.0.0.1
改成
bind_address = 0.0.0.0



CouchDB normal operation is performed by the API

[AppleScript]  plain text view  Copy the code
?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 创建数据库
$ curl -X PUT http://localhost:5984/mydb
{"ok":true}
 
# 查看所有数据库
$ curl -X GET http://localhost:5984/_all_dbs
["mydb"]
 
# 查看数据库信息
$ curl -X GET http://localhost:5984/mydb | json_reformat
{
    "db_name": "mydb",
    "purge_seq": "0-g1AAAAFTeJzLYWBg4MhgTmEQTM4vTc5ISXIwNDLXMwBCwxygFFMeC5BkeACk_gNBViIDQbUHIGrvE6N2AUTtfmLUNkDUzsevNikBSCbVE3RrkgNIXTxhdQogdfYE1SUyJMlDFGUBAD9sXo4",
    "update_seq": "0-g1AAAAFTeJzLYWBg4MhgTmEQTM4vTc5ISXIwNDLXMwBCwxygFFMiQ5L8____sxIZ8ChKUgCSSfaE1TmA1MUTVpcAUldPUF0eC5BkaABSQKXziVG7AKJ2PzFqD0DU3idG7QOIWpB7swBegl6O",
    "sizes": {
        "file": 33992,
        "external": 0,
        "active": 0
    },
    "other": {
        "data_size": 0
    },
    "doc_del_count": 0,
    "doc_count": 0,
    "disk_size": 33992,
    "disk_format_version": 7,
    "data_size": 0,
    "compact_running": false,
    "cluster": {
        "q": 8,
        "n": 1,
        "w": 1,
        "r": 1
    },
    "instance_start_time": "0"
}


Create documents

[AppleScript]  plain text view  Copy the code
?
1
2
$ curl -X POST http://localhost:5984/mydb -d '{"name":"kongxx", "age": 30, "sex": 1}' -H "Content-Type:application/json"
{"ok":true,"id":"a10691778356d48a39f4ec6784000d2c","rev":"1-1b738f642df6eb80b3eb3e2839bbd10f"}


View all documents

[AppleScript]  plain text view  Copy the code
?
1
2
3
$ curl -X GET http://localhost:5984/mydb/_all_docs
{"total_rows":1,"offset":0,"rows":[
{"id":"a10691778356d48a39f4ec6784000d2c","key":"a10691778356d48a39f4ec6784000d2c","value":{"rev":"1-1b738f642df6eb80b3eb3e2839bbd10f"}}


Update Documentation

[AppleScript]  plain text view  Copy the code
?
01
02
03
04
05
06
07
08
09
10
# 先查询一下文档[/b]$ curl -X GET http://localhost:5984/mydb/a10691778356d48a39f4ec6784000d2c
{"_id":"a10691778356d48a39f4ec6784000d2c","_rev":"1-1b738f642df6eb80b3eb3e2839bbd10f","name":"kongxx","age":30,"sex":1}
 
# 更新文档,需要指定 _rev
$ curl -X PUT http://localhost:5984/mydb/a10691778356d48a39f4ec6784000d2c/ -d '{"name":"kongxx", "age": 36, "sex": 1,  "_rev": "1-1b738f642df6eb80b3eb3e2839bbd10f"}'
{"ok":true,"id":"a10691778356d48a39f4ec6784000d2c","rev":"2-9b552a207bbdea7e7b6ce6cb184c6f4e"}
 
# 更新文档后查询
$ curl -X GET http://localhost:5984/mydb/a10691778356d48a39f4ec6784000d2c
{"_id":"a10691778356d48a39f4ec6784000d2c","_rev":"2-9b552a207bbdea7e7b6ce6cb184c6f4e","name":"kongxx","age":36,"sex":1}


Delete Document

[AppleScript]  plain text view  Copy the code
?
1
2
3
4
5
6
7
# 删除文档
$ curl -X DELETE http://localhost:5984/mydb/a10691778356d48a39f4ec6784000d2c?rev=2-9b552a207bbdea7e7b6ce6cb184c6f4e
{"ok":true,"id":"a10691778356d48a39f4ec6784000d2c","rev":"3-60f90d5d7f1866688cbd55833b2b8c3a"}
 
# 查询文档
$ curl -X GET http://localhost:5984/mydb/a10691778356d48a39f4ec6784000d2c
{"error":"not_found","reason":"deleted"}



Delete Database

[AppleScript]  plain text view  Copy the code
?
1
$ curl -X DELETE http://localhost:5984/mydb[/b]{"ok":true}
Published 963 original articles · won praise 11 · views 30000 +

Guess you like

Origin blog.csdn.net/xiaoyaGrace/article/details/105403316