_design/document_typeThese are two views to allow querying based upon document type in the database. With this view, we can get all documents of a certain type, or documents of a certain type in a data range.
document_typeThis view emits as key: [doc_type, Y, M, D, H, M, S].
mapfunction(doc) {
if (!doc.type || !doc.timestamp) return;
var then = new Date(Date.parse(doc.timestamp));
emit([doc.type,
then.getUTCFullYear(), then.getUTCMonth(),
then.getUTCDate(), then.getUTCHours(),
then.getUTCMinutes(), then.getUTCSeconds()], 1);
}reduce: _statsdocument_type_labelThis view simply reverses the ordering of the output key, so: [Y, M, D, H, M, S, doc_type].
mapfunction(doc) {
if (!doc.type || !doc.timestamp) return;
var then = new Date(Date.parse(doc.timestamp));
emit([doc.type,
then.getUTCFullYear(), then.getUTCMonth(),
then.getUTCDate(), then.getUTCHours(),
then.getUTCMinutes(), then.getUTCSeconds()], 1);
}reduce
_stats// Grab all heartbeat documents
nedm.get_database().getView(
'document_type',
'document_type',
{ opts :
{
reduce : false,
endkey : ['heartbeat'],
startkey : ['heartbeat', {}],
descending : true
}
},
function(e, o) {
// .. handle results
});pynedm: