I am trying to create server code to delete an item in a DB, if it was created more than 10 minutes ago.
It's not working, and I've identified that the problem is the var createdAt below is NaN. This throws off all the math below, with the result that
if (minutesOpen 10)
cannot be evaluated.
Here is all the code:
function deleteOpenMarkers() {
var openSpots = Collection.query(dbId, "openSpots");
console.log(openSpots.length);
for(var i = 0; i < openSpots.length; i++) {
Code: Select all
var createdAt = openSpots[i]._createdAt;
var ms1 = Date.parse(createdAt);
var ms2 = new Date().getTime();
var minutesOpen = Math.round((ms2 - ms1)/1000/60 + 420);
var spotId = openSpots[i]._id;
if (minutesOpen 10) {
Collection.deleteObject(dbId, "openSpots", spotId);
} else {
console.log("spot still open");
}
}
}
deleteOpenMarkers();
Any help much appreciated!