Try this
It seems like you are using MongoDB atlas
mongoose
.connect( uri, { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true })
.then(() => console.log( 'Database Connected' ))
.catch(err => console.log( err ));
and go to your MongoDB Atlas
-> NetworkAccess
-> Edit
-> and add Current IP address
it works!!