node.js接口
mongoDB
原来运行一切正常,今天接口报错,提示如下:
在 customer 集合查询 {"phone":"13312341234"} 时发生错误 MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
at Timeout._onTimeout (E:\APPLICATION\api\node_modules\mongodb\lib\sdam\topology.js:278:38)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) { '127.0.0.1:27017' => [ServerDescription] },
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: null,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined,
[Symbol(errorLabels)]: Set(0) {}
}
从以上提示获得有用的信息connect ECONNREFUSED 127.0.0.1:27017
at Timeout._onTimeout,于是按以下步骤检查。
1. 检查bin目录下的配置文件mongod.cfg,检查network interfaces项的port和ip是否与连接字符串一致。
2.windows快捷键Win+R,输入service.msc,找到MongDB服务程序,如果未启动选择启动,如果已启动选择重启动。如图:
再测试接口已正常。