Reputation: 3112
I am new to mongodb, node.js and express and was making a small sample code and got hit through this error.
app.get('/',function(req, res){
mongoclient.connect('mongodb://localhost:27017/views', function(err, db)
{
var db=mongoclient.db('courses');
db.collection('hello_mongo_express').findOne({}, function(err, doc)
{
res.render('hello', {'name': 'MongoDB'});
});
});
});
And this is the error
oroborus@Saras-Dell-System-XPS-L502X:~/views$ node app.js
Connected correctly to server
/home/oroborus/node_modules/mongodb/lib/mongo_client.js:406
throw err
^
TypeError: Object #<MongoClient> has no method 'db'
at /home/oroborus/views/app.js:19:22
at /home/oroborus/node_modules/mongodb/lib/mongo_client.js:403:11
at process._tickCallback (node.js:415:13)
I referred these link but none of these seem to help.
SO ques
Mongo DB documentation
Please help. Thanks
Upvotes: 0
Views: 278
Reputation: 703
I would make sure you are you using the current version of the driver and try mongoclient.connect, rather than going back to a legacy version of the driver.
"mongoclient.open" is from version 1.4.9 found [here].1 The current version is http://mongodb.github.io/node-mongodb-native/2.0/
Upvotes: 0
Reputation: 97
I had the same problem with mongodb node package version 2.0.27, using 1.3.10 version instead fixed the problem.
Upvotes: 1