MongoSkin “Cannot read property 'apply' of undefined”

假装没事ソ 提交于 2019-12-07 18:14:28

问题


I'm trying to use MongoSkin in NodeJS, and I have this code:

var mongoskin = require('mongoskin');
var db = mongoskin.db("mongodb://localhost:27017/database");

var collection = db.collection('test');
collection.find().toArray(function(err, items) {
    db.close();
});

yet it returns this error:

TypeError: Cannot read property 'apply' of undefined
    at EventEmitter.<anonymous> (C:\Users\user\node_modules\mongoskin\lib\collection.js:51:21)
    at Object.onceWrapper (events.js:273:13)
    at EventEmitter.emit (events.js:182:13)
    at C:\Users\user\node_modules\mongoskin\lib\utils.js:134:27
    at result (C:\Users\user\node_modules\mongodb\lib\utils.js:414:17)
    at executeCallback (C:\Users\user\node_modules\mongodb\lib\utils.js:406:9)
    at err (C:\Users\user\node_modules\mongodb\lib\operations\mongo_client_ops.js:286:5)
    at connectCallback (C:\Users\user\node_modules\mongodb\lib\operations\mongo_client_ops.js:241:5)
    at process.nextTick (C:\Users\user\node_modules\mongodb\lib\operations\mongo_client_ops.js:463:7)
    at process._tickCallback (internal/process/next_tick.js:61:11)

I have also tried using this code

var mongoskin = require('mongoskin');
var db = mongoskin.db("mongodb://localhost:27017/database");

db.bind('test');
db.test.find().toArray(function(err, array) {
   db.close();
});

I am looking at examples from https://www.npmjs.com/package/mongoskin, and I am also relatively new to MongoDB and MongoSkin. What am I doing wrong to receive this error, and how can I fix it? Thanks in advance.


回答1:


It is dependency problem, latest mongoskin is 2.1.0, it depends on mongodb 2.x. Error occurred if using the latest mongodb 3.x.



来源:https://stackoverflow.com/questions/53900890/mongoskin-cannot-read-property-apply-of-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!