COUCHDB Server address: 127.0.0.1
Port: 5984
Add a Database
Connect to Couchdb
Curl-x GET http://127.0.0.1:5984
{"Couchdb": "Welcome", "uuid": "1c81fc63d761c82c4f48bac34afd5eb8", "Version": "1.6.0", "Vendor": {"name": "The Apache Software Foundation "," Version ":" 1.6.0 "}}
Create a database DB1
Curl-x PUT HTTP://127.0.0.1:5984/DB1
{"OK": true}
Create a database DB2
Curl-x PUT HTTP://127.0.0.1:5984/DB2
{"OK": true}
List all current databases
Curl-x GET Http://127.0.0.1:5984/_all_dbs
["_replicator", "_users", "DB1", "DB2"]
Delete DB2 Database
Curl-x DELETE HTTP://127.0.0.1:5984/DB2
{"OK": true}
Delete Succeeded
Database operations
-
Add data to the database
First, get a UUID
Curl-x get/HTTP/ 127.0.0.1:5984/_uuids
{"UUIDs": ["1925A2A284289DF9B55B390525001CA1"]} 
Note: The UUID is different each time it is obtained.
Get 10 uuid:curl-x get http://127.0.0.1:5984/_uuids?count=10
inserts a data using the UUID as a key
Curl-x PUT http://127.0.0.1:5984/db1/1925a2a284289df9b55b390525001ca1-d ' {"title": "Test", "Content": " This is test! "}"
{"OK": true, "id": "1925A2A284289DF9B55B390525001CA1", "Rev": "1-4d3e6350fdcc39f7b482c4cab8ff5d9a"}
Update record
Curl-x PUT http://127.0.0.1:5984/db1/1925a2a284289df9b55b390525001ca1-d ' {"title": "Test", "Content": "This is test! modifyied! "}"
{"Error": "Conflict", "Reason": "Document update conflict."}
Have failed. Because, COUCHDB is submitted by version, the same source commits several times, causing some confusion. Therefore, it is controlled using a version.
Curl-x PUT http://127.0.0.1:5984/db1/1925a2a284289df9b55b390525001ca1-d ' {"_rev": " 1-4d3e6350fdcc39f7b482c4cab8ff5d9a "," title ":" Test "," Content ":" This is test! "} '
{"OK": true, "id": "1925A2A284289DF9B55B390525001CA1", "Rev": "2-f6f24194b29981316f2412e288cda320"}
There's no problem with that.
Get Records
Curl-x GET HTTP://127.0.0.1:5984/DB1/1925A2A284289DF9B55B390525001CA1
{"_id": "1925A2A284289DF9B55B390525001CA1", "_rev": "2-f6f24194b29981316f2412e288cda320", "title": "Test", "content" : "This is test!"}
List all documents under the DB1 Library
Curl-x GET Http://127.0.0.1:5984/db1/_all_docs
{"Total_rows": 2, "offset": 0, "Rows": [
{"id": "1925A2A284289DF9B55B390525001CA1", "Key": "1925A2A284289DF9B55B390525001CA1", "value": {"Rev": "2- F6f24194b29981316f2412e288cda320 "}},
{"id": "1925a2a284289df9b55b390525002c29", "Key": "1925a2a284289df9b55b390525002c29", "value": {"Rev": " 1-4a1158c264f8cc636e1fc54a7a696de6 "}}
]}
Deleting records
Curl-x DELETE http://127.0.0.1:5984/db1/1925a2a284289df9b55b390525001ca1?rev=2-f6f24194b29981316f2412e288cda320
Uploading attachments
Curl-x PUT http://127.0.0.1:5984/db1/40dab8a067c56aef572307dd1f0119c8-d ' {"title": "Test", "Content": "This is test!"} '
Curl-x PUT http://127.0.0.1:5984/db1/40dab8a067c56aef572307dd1f0119c8/atwork.jpg?rev=2-2739352689--data-binary @ Atwork.jpg-h "Content-type:image/jpg"
Atwork.jpg is the picture file under the current directory.
Database replication
-
local replication
Curl-x PUT http://127.0.0.1:5984/albums-replica
Curl-x POST HT Tp://127.0.0.1:5984/_replicate-d ' {' source ': ' albums ', ' Target ': ' Albums-replica '} '-H ' content-type:application/ JSON "
-
Local to remote replication
Curl-x POST http://127.0.0.1:5984/_replicate-d ' {" Source ":" Albums "," Target ":" Http://example.org:5984/albums-replica "} '-H" content-type:application/json "
If the remote server has a password, This format can be used: Http://username:[email protected]:5984/demo
-
remote to local
Curl-x POST http://127.0.0.1:5984/_replicate-d ' {"source": "Http://example.org:5984/albums-replica", "Target": "Albums"} '- H "Content-type:application/json"
-
remote to remote
Curl-x POST http://127.0.0.1:5984/_ Replicate-d ' {' source ': ' http://example.org:5984/albums ', ' target ': ' Http://example.org:5984/albums-replica '} '-h ' Content-type:application/json "
Curl Operation Couchdb