ytab2a
Last Updated: February 25, 2016
·
1.185K
· runexec
81609937c20aeab3598aea56f1f4f022

Javascript: The language of CouchDB

CouchDB replaces SQL Queries with JavaScript MapReduce AKA. views. A view returns a range of objects in the database, and the developer has to decide either to do the calculations on the db or on the client.

The following example will display documents with the _id of "tester". Notice the optional server-side logic in this request

function(doc) {
  theData = "Revision: "+doc._rev+" Key: "+doc._id;
  theKey = "Custom Key "+doc._id;
  if(doc._id == "tester"){ emit(theKey, theData); }
}

endorse