

function(doc){ if (!doc.tags || !isArray(doc.tags) || !doc.type || doc.type != 'post'){ return; } for (var idx in doc.tags){ emit(doc.tags[idx].toLower(), 1); } }
function(doc, req){ if (!doc){ if ('id' in req){ // create new document return [{'_id': req['id']}, 'New World'] } // change nothing in database return [null, 'Empty World'] } doc['world'] = 'hello'; doc['edited_by'] = req['userCtx']['name'] return [doc, 'Edited World!'] }
function(newDoc, oldDoc, userCtx, secObj){
function require(field, message){
message = message;
if(!newDoc[field]){throw({forbidden: message})}
}
if(newDoc.doc_type == "Command"){
require("name");
require("command");
}
if(oldDoc && oldDoc.doc_type == ("Command" || "Host") && newDoc.name != oldDoc.name){
throw({forbidden: 'The host name cannot be changed'});
}
}function(doc, req){ if (doc){ return "Hello from " + doc._id + "!"; } else { return "Hello, world!"; } }
function(head, req){ start({ 'headers': { 'Content-Type': 'text/html' } }); send('<html><body><table>'); send('<tr><th>ID</th><th>Key</th><th>Value</th></tr>') while(row = getRow()){ send(''.concat( '<tr>', '<td>' + toJSON(row.id) + '</td>', '<td>' + toJSON(row.key) + '</td>', '<td>' + toJSON(row.value) + '</td>', '</tr>' )); } send('</table></body></html>'); }
function(doc, req){ // we need only `mail` documents if (doc.type != 'mail'){ return false; } // we're interested only in `new` ones if (doc.status != 'new'){ return false; } return true; // passed! }