这是堆栈跟踪:当我在项目中运行server.js文件时,就会发生这种情况。另外,我在网上找不到任何解释。有人可以帮忙解决这个错误吗?
E:\users\ashane\documents\visual studio 2015\Projects\ShowTracker\ShowTracker\node_modules\agenda\lib\agenda.js:341
if ( this._mdb.s.topology.connections().length === 0 ) { ^
TypeError: Cannot read property 's' of undefined
at Agenda._findAndLockNextJob (E:\users\ashane\documents\visual studio 2015\Projects\ShowTracker\ShowTracker\node_modules\agenda\lib\agenda.js:341:17) at jobQueueFilling (E:\users\ashane\documents\visual studio 2015\Projects\ShowTracker\ShowTracker\node_modules\agenda\lib\agenda.js:420:10) at processJobs (E:\users\ashane\documents\visual studio 2015\Projects\ShowTracker\ShowTracker\node_modules\agenda\lib\agenda.js:404:7)
at doNTCallback0 (node.js:417:9)
at process._tickCallback (node.js:346:13)
at Function.Module.runMain (module.js:469:11)
at startup (node.js:134:18)
at node.js:961:3
这些是唯一使用议程和“s”
var mongoConnectionString = "mongodb://127.0.0.1/agenda";
var agenda = require('agenda')({ db: { address: mongoConnectionString } });
var sugar = require('sugar');
var nodemailer = require('nodemailer');
// define an agenda job called send email alert.
agenda.define('send email alert', function (job, done) {
// what should happen when send email alert job is dispatched.
// When this job runs, name of the show will be passed in as an optional data object.
// Since we are not storing the entire user document in subscribers array (only references),
// we have to use Mongoose’s populate method.
Show.findOne({ name: job.attrs.data }).populate('subscribers').exec(function (err, show) {
var emails = show.subscribers.map(function (user) {
return user.email;
});
var upcomingEpisode = show.episodes.filter(function (episode) {
return new Date(episode.firstAired) > new Date();
})[0];
var smtpTransport = nodemailer.createTransport('SMTP', {
service: 'SendGrid',
auth: { user: 'hslogin', pass: 'hspassword00' }
});
// standard Nodemailer boilerplate for sending emails.
var mailOptions = {
from: 'Fred Foo ✔ <[email protected]>',
to: emails.join(','),
subject: show.name + ' is starting soon!',
text: show.name + ' starts in less than 2 hours on ' + show.network + '.\n\n' +
'Episode ' + upcomingEpisode.episodeNumber + ' Overview\n\n' + upcomingEpisode.overview
};
smtpTransport.sendMail(mailOptions, function (error, response) {
console.log('Message sent: ' + response.message);
smtpTransport.close();
done();
});
});
});
agenda.start();
agenda.on('start', function (job) {
console.log("Job %s starting", job.attrs.name);
});
agenda.on('complete', function (job) {
console.log("Job %s finished", job.attrs.name);
});
最佳答案
在议程.js中,在if ( this._mdb.s.topology.connections().length === 0 )
行中,this._mdb
是未定义的。
方法Agent.prototype.database
将_mdb
中返回的db
对象分配给MongoClient.connect
。所以我的猜测是连接操作失败。您确定您的连接字符串吗?