我检查MongoDB服务是否正在运行,我可以连接MongoDB unsing /bin/mongo.exe 但是我无法使用nodejs驱动程序连接到MongoDB服务器。
我的代码在Windows 10上运行。错误消息如下。
C:\Documents and Settings\Administrator\Desktop\src\server>node server.js
Listening on port 80
C:\Documents and Settings\Administrator\Desktop\src\server\node_modules\mongodb\
lib\mongo_client.js:225
throw err
^
MongoError: failed to connect to server [127.0.0.1:27017] on first connect
at null.<anonymous> (C:\Documents and Settings\Administrator\Desktop\src\ser
ver\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:313:
35)
at emitOne (events.js:77:13)
at emit (events.js:169:7)
at null.<anonymous> (C:\Documents and Settings\Administrator\Desktop\src\ser
ver\node_modules\mongodb\node_modules\mongodb-core\lib\connection\pool.js:260:12
)
at g (events.js:260:16)
at emitTwo (events.js:87:13)
at emit (events.js:172:7)
at Socket.<anonymous> (C:\Documents and Settings\Administrator\Desktop\src\s
erver\node_modules\mongodb\node_modules\mongodb-core\lib\connection\connection.j
s:162:49)
at Socket.g (events.js:260:16)
at emitOne (events.js:77:13)
答案 0 :(得分:0)
使用较低版本的mongodb驱动程序。 在这种情况下,我使用1.4。