我的代码
var User = require('./models/user');
var CronJob = require('cron').CronJob;
var job = new CronJob('0-59 0-59 0-23 * * 0-6', function(req, res) {
User.find(function(err, user) {
console.log("CRON is started !" + user.email)
});
}, function () {
/* This function is executed when the job stops */
console.log("CRON is stoped !")
},
true /* Start the job right now */
);
答案 0 :(得分:0)
我猜你正在使用Mongoose来处理与MongoDB相关的东西,你定义了自己的用户模型。 MongoDb的结果将是一个对象数组,因此user.email
是不可能的。您必须遍历数组中所有返回的对象。
尝试使用:
// get all the users
User.find({}, function(err, users) {
// optional but i would recommend to use it so that you can see possible errors with your query
if (err) throw err;
// iterate over all users of all the users
users.forEach(function(user) {
console.log("CRON is started !" + user.email);
});
});