CouchDB 不更新即将发生和过去的事件的视图
我在 couchdb 上有以下视图,它只会返回日期大于当前日期的文档,例如:
function (doc) {
var eventDay = new Date(new Date(doc.start).toDateString()),
currentDay = new Date(new Date().toDateString());
if (eventDay > currentDay) {
emit();
}
}
因此在这种情况下,视图将始终仅显示未来(即将到来的)事件。我也有相同的倒置视图,仅显示过去的事件。但问题是,显然第二天视图不会更新。所以我必须通过添加一些换行符来手动更新视图,所以我想这会导致“刷新”。
关于如何使这项工作有效的任何想法?
多谢
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 view 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要忘记每个条目的地图代码是在文档创建/更改时执行的,因此您将不会获得您所认为的“currentDay”的一致值。
相反,您必须构建一个允许您在查询期间添加此信息的视图。这是一个示例:
这将创建一个复杂的索引,按(年、月、日)排序。您现在可以使用 startkey/endkey 查询部分范围,例如未来的所有日期。有关详细信息,请参阅查看 API:http://wiki.apache.org/couchdb/HTTP_view_API
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:
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