流星';当Meteor.publish带有“s”时,乐观的用户界面被破坏;createdAt:{$gte:start,$lt:now}";

流星';当Meteor.publish带有“s”时,乐观的用户界面被破坏;createdAt:{$gte:start,$lt:now}";,meteor,angular-meteor,optimistic-ui,Meteor,Angular Meteor,Optimistic Ui,故事: 我使用了meteor 1.4和angular 1。我想使用Meteor.publish将“Todo”设置为私有,以下是客户端代码: var now = new Date(); var start = new Date(); start.setHours(0, 0, 0, 0); this.helpers({ todos() { return Todos.find({createdAt: {$gte: start, $lt: now}, userId: Meteor.use

故事: 我使用了meteor 1.4和angular 1。我想使用Meteor.publish将“Todo”设置为私有,以下是客户端代码:

var now = new Date();
var start = new Date();
start.setHours(0, 0, 0, 0);
this.helpers({
    todos() {
    return Todos.find({createdAt: {$gte: start, $lt: now}, userId: Meteor.userId()}, {
            sort: {
                createdAt: -1
            }
        });
    },
    currentUser() {
        return Meteor.user();
    }
});
问题: 当我使用带有“userId”的
Meteor.publish
时,todo列表ui运行良好,在我添加一个新的todo后,它可以自动更新ui。但是在我添加了
Meteor.publish
createdAt:{$gte:start,$lt:now}过滤器后,我必须刷新(F5)页面,然后才能看到新的todo。以下是服务器端发布代码:

Meteor.publish('todos', function tasksPublication() {
     var now = new Date();
     var start = new Date();
     start.setHours(0, 0, 0, 0);
     return Todos.find({createdAt: {$gte: start, $lt: now}, userId: this.userId});
});

有人知道如何修复吗?

我已经修复了这个错误。由于我没有深入流星的缓存,下面的原因是我的猜测:

  • 客户端UI正在绑定到缓存(miniMongo)的“Todos.find({createdAt:{$gte:start,$lt:now},userId:this.userId})”
  • 插入一个新todo后,它将首先插入到miniMongo
  • miniMongo重新运行1次查询,但“现在”是1次“现在”。发现#2的结果不合适。所以它从客户端删除了新记录
  • 这是找我的零钱:

    如果你有任何不同的想法,请告诉我


    谢谢。

    我已经修复了这个错误。由于我没有深入流星的缓存,下面的原因是我的猜测:

  • 客户端UI正在绑定到缓存(miniMongo)的“Todos.find({createdAt:{$gte:start,$lt:now},userId:this.userId})”
  • 插入一个新todo后,它将首先插入到miniMongo
  • miniMongo重新运行1次查询,但“现在”是1次“现在”。发现#2的结果不合适。所以它从客户端删除了新记录
  • 这是找我的零钱:

    如果你有任何不同的想法,请告诉我

    谢谢