Search code examples
node.jsmongodbmongoskin

MongoSkin "Cannot read property 'apply' of undefined"


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.


Solution

  • 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.