node.js - error connecting to mongodb with mongoose on google compute engine -


i'm following bookshelf app tutorial. able deploy app , have server running , connect mongodb instance. working fine. when tried deploy own app, followed steps, able code cloud repository. started linux debian vm , supplied startup script found in tutorial when went address

http://<your-instance-ip>:8080 

i wasn't able connect application. sshd instance , able navigate directory in file saved, , manually entered command

node app.js 

i immedietly got console log application running on port 8080. after 10 minutes, got error application wasn't able connect mongodb instance. use mongoose connect mongodb whereas in tutorial used mongoclient. here code:

mongoose.connect('mongodb://***.***.***.***:27017/myappdatabase'); var db = mongoose.connection; db.on('error', console.error.bind(console, 'connection error:'));  db.once('open', function(callback) {     console.log("connected mongodb..."); }); 

and here tutorial code:

mongoclient.connect(url, function(err, db) {   if (err) {     console.log(err);     return cb(err);   }   collection = db.collection(collectionname);   cb(null, collection); }); 

where url same url in mongoose.connect();

i'm pretty sure problem. when vm spins up, executes app.js file , when it's not able connect mongodb, server collapses.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -