类型错误:无法读取事件发射器处未定义的属性'apply'



我正在构建一个节点js应用程序,其中DHTMLX调度程序是页面之一。但是,当页面加载时,应用程序崩溃,我收到以下错误:

类型错误:无法读取事件发射器处未定义的属性"apply"。(/node_modules/mongoskin/lib/collection.js:52:21((

以下是错误引用的模块:

  SkinCollection.prototype._open = function(callback) {
    var collection_args = this._collection_args.concat([callback]);
    this._skin_db.open(function(err, db) {
        if(err) return callback(err);
        db.collection.apply(db, collection_args);
    });
  }

这是我的应用程序的部分.js导致错误,当我不包含此代码时,日历不会使应用程序崩溃,但我无法将数据发送到我的MongoDB atlas集群。

应用.js

    app.use(express.static(path.join(__dirname, 'public')));
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: true }));
    app.get('/init', function(req, res){
        db.event.insert({ 
            text:"My test event A", 
            start_date: new Date(2018,8,1),
            end_date:   new Date(2018,8,5)
        });
        db.event.insert({ 
            text:"My test event B", 
            start_date: new Date(2018,8,19),
            end_date:   new Date(2018,8,24)
        });
        db.event.insert({ 
            text:"Morning event", 
            start_date: new Date(2018,8,4,4,0),
            end_date:   new Date(2018,8,4,14,0)
        });
        db.event.insert({ 
            text:"One more test event", 
            start_date: new Date(2018,8,3),
            end_date:   new Date(2018,8,8),
            color: "#DD8616"
        });
        res.send("Test events were added to the database")
    });

    app.get('/data', function(req, res){
        db.event.find().toArray(function(err, data){
            //set id property for all records
            console.log(err);
            for (var i = 0; i < data.length; i++)
                data[i].id = data[i]._id;
            //output response
            res.send(data);
        });
    });

    app.post('/data', function(req, res){
        var data = req.body;
        var mode = data["!nativeeditor_status"];
        var sid = data.id;
        var tid = sid;
        delete data.id;
        delete data.gr_id;
        delete data["!nativeeditor_status"];

        function update_response(err, result){
            if (err)
                mode = "error";
            else if (mode == "inserted")
                tid = data._id;
            res.setHeader("Content-Type","application/json");
            res.send({action: mode, sid: sid, tid: tid});
        }
        if (mode == "updated")
            db.event.updateById( sid, data, update_response);
        else if (mode == "inserted")
            db.event.insert(data, update_response);
        else if (mode == "deleted")
            db.event.removeById( sid, update_response);
        else
            res.send("Not supported operation");
    });

我在过去的一周里一直在学习javascript,对编码非常陌生。我不明白为什么会发生此错误。当我将调度程序应用程序作为独立功能运行时,它可以完美运行。只有当我尝试在我的网站中实现它时,它才会抛出此错误。

更新:正确答案

此问题是重复的:MongoSkin"无法读取未定义的属性'应用'">

Mongoskin仅支持MongoDB 2.x,使用MondoDB 3.x时会发生此错误。

原始(不正确(答案

我自己对MongoDB来说很新,但我很确定问题是你需要用这一行上表的实际名称替换collection

db.collection.apply(db, collection_args);

例如,如果表/集合的名称skin,则该行将变为:

db.skin.apply(db, collection_args);

(请注意,当app.j在事件表上执行数据库操作时,它是如何调用db.event.insert()等的......

最新更新