我在Ubuntu上安装了MongoDb Community
,并希望从我的其他服务器连接到它。
在/etc/mongod.conf
文件中,当我评论这些行时,它可以工作:
# security:
# authorization: 'enabled'
但是当我取消注释时,我收到了这个错误:
No connection could be made because the target machine actively refused it
在两种情况下都会注释bindIp
# bindIp: 127.0.0.1
安装后,我以这种方式创建了一个用户:
use DataDb
db.createUser({
user: 'u1',
pwd: 'secretPassword',
roles: [{ role: 'readWrite', db:'DataDb'}]
})
我的连接字符串是这样的:
var client = new MongoClient("mongodb://u1:pass@xxx.xx.xxx.xxx:27017/DataDb");
有什么问题?感谢。