javascript - Synced Cron Expire on Simple Schema -
i'm having trouble setting cron job percolate:synced-cron package expire collection entries based on simple schema date , time fields. there way this, or doing wrong?
i'm receiving following error below:
typeerror: posts.find(...).toarray not function
synced cron code
syncedcron.start(); syncedcron.add({ name: 'expire events', schedule: function(parser) { // parser later.parse object return parser.text('every 15 minutes'); }, job: function() { expiretoday = posts.find ({ date: new date().toisostring().substring(0,10) }).toarray(); console.log(expiretoday); (i = 0; < expiretoday.length; i++) { expireid = expiretoday.eq(i)._id; console.log(expireid); if (expiretoday.eq(i).time < new date().totimestring().substring(0,5)) { posts.deleteone({_id : expireid}); } } } });
simple schema coffee code
schemas.posts = new simpleschema title: type:string max: 60 optional: true content: type: string optional: true autoform: rows: 5 createdat: type: date autovalue: -> if this.isinsert new date() updatedat: type:date optional:true autovalue: -> if this.isupdate new date() time: type: string optional: false autoform: affieldinput: type: 'time' date: type: string optional: false autoform: affieldinput: type: 'date' owner: type: string regex: simpleschema.regex.id autovalue: -> if this.isinsert meteor.userid() autoform: options: -> _.map meteor.users.find().fetch(), (user)-> label: user.emails[0].address value: user._id
example mongo date , time
"date" : "2017-09-10" "time" : "01:01"
the error message telling failed:
expiretoday = posts.find ({ date: new date().toisostring().substring(0,10) }).toarray();
it means posts.find()
didn't return converted array.
it returns cursor, maybe meant add .fetch()
array of objects?
in either case should check return of call make sure returning expect - basic defensive coding practice
Comments
Post a Comment