javascript - No connection events are being fired - Mongoose 4.7.1 & Express -
i having issues connecting express app mongodb via mongoose. there no complicated set up, basic:
var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/homeapp'); var db = mongoose.connection; db.on("connecting", function(){ console.log("connecting db..."); }); db.on('connected', function(){ console.log('connected db'); }); db.on('error', function(error){ console.log('error'); });
simple enough, right? none of these events being fired. mongo running ok , it's on default port. have tried changing localhost
127.0.0.1
, checked contents of etc/hosts
file , seems ok. if mangle uri string like:
'mongoldb://lclhost/homeapp'
i error saying cannot connect, expected seems connection being made/attempted nothing happening.
i've logged contents of db.db
console , noticed connected: false
, suggests it's not attempting connect?
any ideas? mongoose 4.7.1 running on macos sierra 10.12.5.
thanks in advance!
figured it! tried using mongodb client without mongoose , worked expected, knew connection ok , left blame mongoose.
turns out not using 4.7.1 had thought, , running npm install mongoose --save
had in fact installed version 3.x, not compatible latest version of mongodb according mongoose docs. http://mongoosejs.com/docs/compatibility.html
upgrading version number in package.json
file 4.7.1 fixed issue.
Comments
Post a Comment