I can connect to a google cloud deployed mongoDB f

2019-08-03 04:24发布

My app is written in React and Express using Mongoose for the db. I deployed a bitnami mongoDB instance on google compute engine. Now I'm trying to deploy the server on the App engine. When I run my app locally it connects fine to the db (I can add stuff and see it). But when I do an npm start in the google cloud shell is get this error:

'failed to connect to server [35.196.182.249:27017] on first connect [MongoError: connection 0 to 35.196.182.249:27017 timed out]' }
(node:1310) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): MongoError: failed to connect to server [35.196.182.249:27017] on first connect [MongoError: connection 0 to 35.196.182.249:27017 timed out]

Here is my code to connect:

mongoose.connect(process.env.MONGODB_URI,{
    useMongoClient: true
}).catch(function(err){
    console.log(err)
});

where MONGODB_URI=mongodb://root:password@XX.XXX.XXX.XXX:27017, password is the password I got from the compute engine, and XX.XXX.XXX.XXX is the external IP provided by the compute engine. I use the same URI when connecting locally and in the google cloud shell but it only connects from localhost. I tried hardcoding in the URI too and it didn't work. Any ideas?

0条回答
登录 后发表回答