Hello, so I’m a bit confused why what I’m trying to do isn’t working. Basically I am trying to check if from the current subscribed list of WeeklyCopays if a weekStartDate within the last 5 Sundays has already been created, if not then add to the list dateList. Code below showing what I am trying to do.
However the “var hold = WeeklyCopays.findOne({weekStartDate: d});” always returns nothing, even when I know there is a weekStartDate with that date. But what confuses me even more is that “this.copays = WeeklyCopays.find({}, { sort: { weekStartDate: -1 } });” from the code below does work and returns a list of WeeklyCopays.
Am still very new to all of this and have no idea what I maybe doing wrong here. Or if there is a better way to accomplish what I am trying to do.
export class CopaysList extends MeteorComponent {
copays: Mongo.Cursor<Object>;
dateList = [];
constructor(params: RouteParams) {
super();
this.autorun(() => {
this.subscribe('user.WeeklyCopays', params.get('userId'), () => {
this.copays = WeeklyCopays.find({}, { sort: { weekStartDate: -1 } });
}, true);
});
this.loadDateList();
}
loadDateList(){
for (var index = 0; index < 5; index++) {
var d = new Date();
d = moment().day(index * -7).toDate();
var hold = WeeklyCopays.findOne({weekStartDate: d});
if(!hold)
{
this.dateList[index] = d;
}
}
}
}
Thanks