nodejs连接mongodb出现connection timed out

使用nodejs连接远程mongodb提示连接超时,但是本地的navacat可以正常连接远程
报错如下:

img

nodejs连接数据库代码如下:

var mongoose = require("mongoose"); //引入mongoose

mongoose.connect('mongodb:/host:port/users',{useUnifiedTopology: true, useNewUrlParser: true}); //连接到mongoDB的users数据库  云服务器


//该地址格式:mongodb://[username:password@]host:port/database[?options]
//默认port为27017 
// mongoose.connect(config.mongod.url, config.mongod.options);
mongoose.set('useCreateIndex', true)
var db = mongoose.connection;

db.on('error', function callback(err) { //监听是否有异常
  // console.log("err===>",err)
  console.log("Connection error");
});

db.once('open', function callback() { //监听一次打开
  //在这里创建你的模式和模型
  console.log('mongodb connected!');
});

module.exports = mongoose;

链接字符串改过了吗?还是为了隐私没贴出来?

img

你这个navicat是在服务器上的,没有防火墙问题,别的电脑访问还是有的,腾讯云的防护墙我也试过,还是得在操作系统上输命令才有用

firewall-cmd --zone=public --add-port=27017/tcp --permanent
service firewalld restart