COUCHDB Installation
sudo Install Erlang sudo Install Libmozjs185-dev Libicu-dev
Download source code, compile and install
After startup
Go to admin interface
Http://localhost:5984/_utils
The curd part of the data follows the restful pattern, ignoring it directly, but regarding the query, because the document type is not very good relations processing, so, added a view for map reduce's data query
Make map in Couchdb the query is not complex, the view used for querying and the general document is not much different, there are two different places
Must start with _design and must have an views field, for example
{ "_id":"_design/articles", "_rev":"6-3d7568f84acd59d397e8b0e7f7add7eb", "language":"JavaScript", " views": { " All": { "Map":"function (DOC) {emit (Doc.user_name, Doc.money);}", "Reduce":"function (key, values, rereduce) {return sum (values);}" }, "by_author_id": { "Map":"function (DOC) {if (Doc.type = = ' article ') {emit ([Doc.user_name], doc);} }" } }}
If I had a few figures,
{ "_id":"0C5DF7FF242754705FB3355373001FCA", "_rev":"5-E705B7220C11304FD2212D40B1258BCE", " Money": -, "user_name":"Pig", "type":"article"}{ "_id":"0c5df7ff242754705fb3355373002827", "_rev":"4-b9024f71db567187cc36cadbabecc580", " Money": $, "user_name":"Idiot"}
Query for all query criteria
Map+reduce together
Curl http://127.0.0.1:5984/test_db/_design/articles/_view/all?group=true
Light map, no reduce
Curl http://127.0.0.1:5984/test_db/_design/articles/_view/all?reduce=false
Query by_author_id conditions
Curl http://127.0.0.1:5984/test_db/_design/articles/_view/by_author_id?reduce=false
Look at the results.
Definition in COUCHDB query script support Python,js,erlang, but it seems that JS the simplest point
About replication
The default couchdb is the bound local IP, which needs to be changed to 0. 0.0. 0 database must exist for the destination, or it will fail
Examples of use of COUCHDB