How to change the ip of Mongo for external access

Asked

Viewed 133 times

-1

Good currently I am using Mongo and React, and as usual the application works on 127.0.0.1

But now I also have an external access, so Ngo should also listen from another external ip. How do I make this change?

'Cause when I put the ip, the moongose doesn’t work...

Example

Mongoose.connect('127.0.0.1:27017/mydb') Works ok appears information..

Mongoose.connect('25.10.228.128:27017/mydb') does not work

returns

" name: 'Mongoerror', message: 'failed to connect to server [25.10.228.128:27017] on first connect' "

It is necessary to release so that the user understands that they must also make the data available to those who access from ip 25.10.228.128 ?

1 answer

1

You must put the protocol mongodb://
Otherwise it doesn’t work, but it’s right what you did, that’s all it needs. Here’s a possible example that might suit you:

mongoose.connect('mongodb://25.10.228.128:27017:/mydb', {
    useCreateIndex: true,
    useNewUrlParser: true,
    useUnifiedTopology: true,
    user: 'username',
    pass: 'passwrod'
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.