Examples of use of COUCHDB

Source: Internet
Author: User
Tags emit couchdb

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.