【发布时间】:2019-01-09 16:45:52
【问题描述】:
当我启动我的 mongod 服务器时,它运行得非常好。我打开了所有连接来尝试解决这个问题,所以不要介意警告。当我尝试运行我的节点进程时,它通过其公共 IP 连接到我的服务器(我有那个设置,所以我也可以从家里连接到我的数据库)。但是,我的节点进程实际上从未启动,但 mongo 服务器显示了一个
[conn1] received client metadata from Censored IP: 46534 conn1: {
driver: {
name: "nodejs",
version: "3.1.10"
},
os: {
type: "Linux",
name: "linux",
architecture: "x64",
version: "4.15.0-1031-aws"
},
platform: "Node.js v11.4.0, LE, mongodb-core: 3.1.9"
}
我的mongo配置是:
# for documentation of all options, see: #http: //docs.mongodb.org/manual/reference/configuration-options/
#Where and how to store data.
storage:
dbPath: /var/lib / mongodb
journal:
enabled: true# engine: #mmapv1: #wiredTiger:
#where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log / mongodb / mongod.log
# network interfaces
net:
port: 27017
bindIp: ::, 0.0 .0 .0# bindIpAll: true# how the process runs
processManagement:
timeZoneInfo: /usr/share / zoneinfo
# security: #authorization: enabled# operationProfiling:
#replication:
#sharding:
##Enterprise - Only Options:
#auditLog:
#snmp:
我使用mongoose连接,之前只遇到过一次,暂时修复了,但不知道为什么我的node进程连接不上mongod服务器并正常启动。
蒙古日志:
2019 - 01 - 09 T16: 35: 59.390 + 0000 I STORAGE[initandlisten] WiredTiger message[1547051759: 390412][3431: 0x7f79c7a83a40], txn - recover: Recovering log 25 through 26
2019 - 01 - 09 T16: 35: 59.442 + 0000 I STORAGE[initandlisten] WiredTiger message[1547051759: 442748][3431: 0x7f79c7a83a40], txn - recover: Recovering log 26 through 26
2019 - 01 - 09 T16: 35: 59.486 + 0000 I STORAGE[initandlisten] WiredTiger message[1547051759: 486445][3431: 0x7f79c7a83a40], txn - recover: Set global recovery timestamp: 0
2019 - 01 - 09 T16: 35: 59.530 + 0000 I RECOVERY[initandlisten] WiredTiger recoveryTimestamp.Ts: Timestamp(0, 0)
2019 - 01 - 09 T16: 35: 59.547 + 0000 I CONTROL[initandlisten]
2019 - 01 - 09 T16: 35: 59.547 + 0000 I CONTROL[initandlisten] ** WARNING: Access control is not enabled
for the database.
2019 - 01 - 09 T16: 35: 59.547 + 0000 I CONTROL[initandlisten] ** Read and write access to data and configuration is unrestricted.
2019 - 01 - 09 T16: 35: 59.547 + 0000 I CONTROL[initandlisten]
2019 - 01 - 09 T16: 35: 59.584 + 0000 I FTDC[initandlisten] Initializing full - time diagnostic data capture with directory '/var/lib/mongodb/diagnostic.data'
2019 - 01 - 09 T16: 35: 59.585 + 0000 I NETWORK[initandlisten] waiting
for connections on port 27017
2019 - 01 - 09 T16: 36: 10.088 + 0000 I NETWORK[listener] connection accepted from Censored IP: 46534 #1 (1 connection now open)
2019-01-09T16:36:10.095+0000 I NETWORK [conn1] received client metadata from Censored IP:46534 conn1: { driver: { name: "nodejs", version: "3.1.10" }, os: { type: "Linux", name: "linux", architecture: "x64", version: "4.15.0-1031-aws" }, platform: "Node.js v11.4.0, LE, mongodb-core: 3.1.9" }
如果有人知道出了什么问题,请告诉我!
const mongoose = require('mongoose')
mongoose.connect(process.env.MONGO_URL, {
useNewUrlParser: true
})
我的 .env 是:
MONGO_URL=mongodb://censoredip:27017/theseus
【问题讨论】:
-
你能显示从nodejs代码连接mongodb的代码吗?这可能指向一些东西..
-
是否应该绑定 ip 不是 0.0.0.0 以让它从所有 IP 连接,而不是像 '0.0 .0 .0' 中的空格
-
我在文档页面上阅读:docs.mongodb.com/manual/reference/program/mongod 让它绑定到所有 ipv4 和 ipv6 以防万一
标签: javascript node.js mongodb