A
A
ak_wi2018-12-17 14:54:50
MongoDB
ak_wi, 2018-12-17 14:54:50

How to set up connection to mongodb with VPN enabled?

The problem is the following. I am writing a telegram bot. On Linux, I use windscribe as a VPN so that the bot can connect to the telegram server. The problem is that after turning on the VPN with the windscribe connect command, the connection to the database is interrupted by an error

UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connection 0 to localhost:27017 timed out]

In this case, all work with the database looks like this:
mongoose.connect("mongodb://localhost:27017/cuba", {useNewUrlParser: true});
    const Place = mongoose.model("Place", placesScheme);
    var iataCode = '';
    await Place.findOne({name: place_name}, 'iataCode', function (err, doc) {
        iataCode = doc.iataCode;
    });
    return iataCode;

When the VPN is turned off, the connection to the database works :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
ak_wi, 2018-12-18
@ak_wi

The answer is simple - turn off the windscribe firewall

B
Bobomurod, 2019-01-13
@bobomurod

Use 127.0.0.1 instead of localhost

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question