下面的视图函数用于发出一些条目:
function(doc) {emit(null,{"date":doc.date,"title":doc.title,"txt":doc.txt});}
{"total_rows":7,"offset":0,"rows":[
{"id":"67ebe3755be4edf5c4edf0d96f0023eb","key":null,"value":{"date":"Dec 12,2012","title":"test1","txt":"this is just a test"}},
{"id":"67ebe3755be4edf5c4edf0d96f003120","key":null,"value":{"date":"Nov 11,2012","title":"test2","txt":"this is just a test2"}},
{"id":"67ebe3755be4edf5c4edf0d96f003869","key":null,"value":{"date":"Dec 22,2012","title":"test4","txt":"this is just a test4"}},
{"id":"67ebe3755be4edf5c4edf0d96f003cfd","key":null,"value":{"date":"Aug 21,2010","title":"test5","txt":"this is just a test5"}},
{"id":"67ebe3755be4edf5c4edf0d96f004466","key":null,"value":{"date":"Nov 1, 2010","title":"test6","txt":"this is just a test6"}},
{"id":"67ebe3755be4edf5c4edf0d96f004d9c","key":null,"value":{"date":"Aug 15,2010","title":"test7","txt":"this is just a test7"}},
{"id":"67ebe3755be4edf5c4edf0d96f005d04","key":null,"value":{"date":"Feb 28,2012","title":"test3","txt":"this is just a test3"}}
]}
使用 CouchDB 函数按年和月对条目进行分组的最佳方法是什么?
(以 JSON 格式输出,例如:)
{
"2012":{
"Feb":[{"date":"Feb 28,2012","title":"test3","txt":"this is just a test3"}],
"Nov":[{"date":"Nov 11,2012","title":"test2","txt":"this is just a test2"}],
"Dec":[{"date":"Dec 12,2012","title":"test1","txt":"this is just a test"},
{"date":"Dec 22,2012","title":"test4","txt":"this is just a test4"}]
},
"2010":{
"Aug":[{"date":"Aug 15,2010","title":"test7","txt":"this is just a test7"},
{"date":"Aug 21,2010","title":"test5","txt":"this is just a test5"}],
"Nov":[{"date":"Nov 1, 2010","title":"test6","txt":"this is just a test6"}]
}
}