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

标签 node.js mongodb request mongoose kue

我使用 mongoose 和 Kue 进行流量控制。我将从数据库检索到的对象传递给 Kue。当作业得到处理时,该对象不再具有某些功能,例如 .save() 等。

  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 表示。

关于node.js - Mongoose 和 Kue - Node.js - 传递的对象没有方法保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11521990/

相关文章:

javascript - 模型之间的 Mongoose 关系

ios - 原生脚本 | Firebase 通知不起作用

node.js - 重定向时 Express 上未设置 Csrf token

node.js - 在 KrakenJS/Express 中加载 socket.io 作为模块

ios - Objective-C json 序列化

WCF 设计 - 一个请求和响应对象还是多个?

node.js - LinkedIn API 失败 - Node.js 请求

python - Jupyter 实验室无法安装任何扩展 : Assertion `data' failed

python - 无法使用 pymongo 删除记录

javascript - Angular js 服务器端过滤器和分页