Mongoose和Kue – Node.js – 传递的对象没有方法保存

我正在使用mongoose和Kue的stream量控制。 我将从数据库检索到的对象传递给Kue。 当作业得到处理时,对象已经不再有一些function,比如.save()&others。

jobs.process('process', 5, function(job, done) { var url = job.data.url; var objo = job.data.comp; request({uri:url, json:true}, function(err, res, body) { objo.meta = body; // Here it throw an error that save is note defined // TypeError: Object #<Object> has no method 'save' objo.save(function(err) { if (err) throw err; console.log('Saved data for ' + objo.title); done(); }); }); }); var q = db.Entity.find({}).sort('_id', 1).limit(10); q.execFind(function(err, docs) { docs.forEach(function(objo) { jobs.create('process', { comp : objo, url : 'http://example.com/' + encodeURIComponent(objo.permalink) + '.js' }).save(); }) }); 

提前致谢

这是因为Kue没有完全保存对象,只保存了调用JSON.stringify()的值。 您需要传入对象的id,并将工具中的mongoose表示从数据库中取出。