Story:
I've used meteor 1.4 with angular 1. And I want to make "Todo" private by using Meteor.publish
, here is the client code:
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();
}
});
Problem:
When I used Meteor.publish
with "userId", the todo list ui worked well, it could auto update ui after I added one new todo. But after I added Meteor.publish
filter with createdAt: {$gte: start, $lt: now}
, I have to refresh (F5) the page, then I can see the the new todo. Here is the server side publish code:
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});
});
Anyone know how to fix it?
I've fixed this bug. As I wasn't deep into Meteor's cache, the reason below was my guess:
And here is my change: Code Change
if you have any different idea, please let me know.
Thanks.