I have the following view on couchdb that will only return docs with a date greater than the current date like:
function (doc) {
var eventDay = new Date(new Date(doc.start).toDateString()),
currentDay = new Date(new Date().toDateString());
if (eventDay > currentDay) {
emit();
}
}
So in this case the view will always show future(upcoming) events only. I also have the same inverted 开发者_如何学JAVAview to show only past events. But the problem is that apparently the view is not being updated on the next day. So I have to update the view manually by adding few line breaks and so I guess this causes a ‘refresh’.
Any ideas on how I could make this work?
Thanks a lot
Don't forget that the map code per entry is executed on document creation/change, thus you will not have consistent values for what you regard as "currentDay".
Instead, you must build a view that allows you to add this information during the query. Here is an example:
funciton(doc){
//Extract from date object.
var year = ..;
var month = ..;
var day = ..;
//..
emit([year,month,day], null);
}
This will create an complex index, ordered by (year,month,day). You can now query for partial ranges, for instance all dates in the future, by using startkey/endkey. Please see the View API for details: http://wiki.apache.org/couchdb/HTTP_view_API
精彩评论