Crouchdb (nosql) and database query using map/reduce

Source: Internet
Author: User
Tags couchdb

1. What is nosql-not only SQL?

Nosql data has no mode-no need to define the data structure in advance (nosql is schema free-you don't need to decide the structure up front .)

 

Nosql is not omnipotent. If you are dealing with relational data, we recommend that you use RDBMS (keep in mind that nosql is not a silver bullet. if your data is truly relational, sticking with your RDBMS wocould be the right choice .)

 

2. query nosql database- ing/simplification (MAP/reduce)

What is map/reduce, why MAP/reduce, see http://wiki.huihoo.com/index.php? Title = mapreduce

Map function, used to map a set of key-value pairs into a new set of key-value pairs-list2 map (functor1, list1)

Reduce (simplification) function refers to the appropriate combination of elements in a list-object reduce (functor2, list2)

3. crouchdb introduction-couchdb is a database designed to run on the Internet of today.

  • She is a document-oriented JSON database written in Erlang.
  • It is a highly concurrent database that supports copying, horizontally spanning multiple devices, and fault tolerance (it is a highly concurrent database designed to be easily replicable, horizontally, using SS numerous devices and be fault tolerant .)
  • Nosql Database
  • She is an open-source Apache Fund project.
  • She uses JSON to store data and can access data through restful
  • She uses ing/simplification to index and query Databases

 

 

1. Installation: http://www.couchone.com/get

2. First Appearance of crouchdb-futon

Http: // 127.0.0.1: 5984/

Http: // 127.0.0.1: 5984/_ utils/(this page is actually implemented using the jquery plug-in, http: // 127.0.0.1: 5984/_ utils/script/jquery. couch. JS. This is a good case to learn how to use crouchdb)

3. User Management:

By default, all users can operate and configure databases,

Create an administrator account. Other users can only read and write data, but cannot configure the database (Click fix this)

It is best not to use a Super User to read and write data, because the super user name and password of the class can be easily seen in the client JavaScript-$. Couch. Signup ()

4. Create/modify a document (new document, add field (Id field recommended), and save document)

5. Use curl to create a document: (post, get, put, delete)

Curl-X Post http: // 127.0.0.1: 5984/mycouchshop/-d @ person. JSON-h "Content-Type: Application/JSON"

Or use other HTTP tools

6. Use curl to view all documents

Curl-x get http: // 127.0.0.1: 5984/mycouchshop/_ all_docs

7. Create MAP/reduce Functions

Create document:

{"name":"p1","product":"web","price":10}

{"name":"p1","product":"web","price":20}

{"name":"p1","product":"portal","price":20}

Futon-> temporary View

Map

Function (DOC ){

If (Doc. type = "product" & Doc. Price ){

Emit (Doc. ID, Doc. Price );

}

}

Redue

Function (keys, prices ){

Return sum (prices );

}

Result:

"Web": 30

"Portal": 20

Http://net.tutsplus.com/tutorials/getting-started-with-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.