couchdb id using date code example
Example 1: couchdb id using date
function (doc) {
var datetime = doc._id;
var year = parseInt(datetime.substr(0, 4));
var month = parseInt(datetime.substr(5, 2), 10);
var day = parseInt(datetime.substr(8, 2), 10);
var hour = parseInt(datetime.substr(11, 2), 10);
var minute = parseInt(datetime.substr(14, 2), 10);
emit([doc.widget, year, month, day, hour, minute], 1);
}
Example 2: couchdb id using date
curl -X GET "http://localhost:5984/transactions/_design/widget_count/_view/toss?group_level=1"
{"rows":[
{"key":[20],"value":10},
{"key":[21],"value":20}
]}
curl -X GET "http://localhost:5984/transactions/_design/widget_count/_view/toss?group_level=2"
{"rows":[
{"key":[20,widget],"value":10},
{"key":[21,widget],"value":10},
{"key":[21,thing],"value":10}
]}
Example 3: couchdb id using date
function(doc) {
var dt = new Date(doc._id);
emit([dt.getDate(), doc.widget], 1);
}