Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database 已更改MongoDB端口,但仍尝试默认端口_Database_Mongodb - Fatal编程技术网

Database 已更改MongoDB端口,但仍尝试默认端口

Database 已更改MongoDB端口,但仍尝试默认端口,database,mongodb,Database,Mongodb,我在/etc/mongod.conf文件ie中更改了端口 net: port: 12345 bindIp: 127.0.0.1,123.123.23.255 #localhost and server pub ip 然后我重新启动了mongo sudo systemctl restart mongod.service 并检查了所有ok: sudo systemctl status mongod mongod.service - High-performance, schema-fr

我在/etc/mongod.conf文件ie中更改了端口

net:
  port: 12345
  bindIp: 127.0.0.1,123.123.23.255 #localhost and server pub ip
然后我重新启动了mongo

sudo systemctl restart mongod.service
并检查了所有ok:

sudo systemctl status mongod

mongod.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2018-07-10 13:35:14 UTC; 16s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 1927 (mongod)
    Tasks: 23
   Memory: 136.3M
      CPU: 1.240s
   CGroup: /system.slice/mongod.service
           └─1927 /usr/bin/mongod --config /etc/mongod.conf
然后我尝试登录到mongo:

mongo --username me --password my_password --authenticationDatabase authdb
并得到以下错误:

MongoDB shell version v3.6.5
connecting to: mongodb://127.0.0.1:27017
2018-07-10T13:29:14.716+0000 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-07-10T13:29:14.717+0000 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
然后,我在mongod.conf中将端口更改回27017,并可以登录到db OK


知道为什么mongo shell会在mongo端口更改的情况下尝试27017吗?

您混淆了mongo服务器(更改.conf文件时配置的服务器)和用于连接mongo服务器的mongo客户端。如果将端口更改为12345,则在尝试连接时必须精确设置端口,并在connecting命令中提供:

mongo--username me--password my_password--authenticationDatabase authdb--port 12345

mongo--username me--password my_password--authenticationDatabase authdb--host 127.0.0.1:12345

编辑:在mongo命令中没有任何端口规范,将使用默认端口规范,因此为27017。

谢谢,根据此处的说明,在没有任何参数的情况下,构造MongoClient实例将连接到“localhost”端口27017。