2017-02-12 103 views
0

这就是我得到当我运行service mongod statusMongoDB是运行但仍然无法连接

● mongod.service - LSB: An object/document-oriented database 
    Loaded: loaded (/etc/init.d/mongod; bad; vendor preset: enabled) 
    Active: active (running) since Sun 2017-02-12 15:05:42 UTC; 4min 59s ago 
    Docs: man:systemd-sysv-generator(8) 
    Process: 6984 ExecStop=/etc/init.d/mongod stop (code=exited, status=0/SUCCESS) 
    Process: 6998 ExecStart=/etc/init.d/mongod start (code=exited, status=0/SUCCESS) 
    CGroup: /system.slice/mongod.service 
      └─7009 /usr/bin/mongod --config /etc/mongod.conf 

Feb 12 15:05:41 WGJG008 systemd[1]: Stopped LSB: An object/document-oriented database. 
Feb 12 15:05:41 WGJG008 systemd[1]: Starting LSB: An object/document-oriented database... 
Feb 12 15:05:41 WGJG008 mongod[6998]: * Starting database mongod 
Feb 12 15:05:42 WGJG008 mongod[6998]: ...done. 
Feb 12 15:05:42 WGJG008 systemd[1]: Started LSB: An object/document-oriented database. 
Feb 12 15:08:25 WGJG008 systemd[1]: Started LSB: An object/document-oriented database. 

但是每当我跑我的服务器

sudo node server.js 

我收到以下错误信息:

MongoError: failed to connect to server [soren_site:27017] on first connect 
at null.<anonymous> (/var/www/soren_api/node_modules/mongodb-core/lib/topologies/server.js:325:35) 
at emitOne (events.js:77:13) 
at emit (events.js:169:7) 
at null.<anonymous> (/var/www/soren_api/node_modules/mongodb-core/lib/connection/pool.js:270:12) 
at g (events.js:260:16) 
at emitTwo (events.js:87:13) 
at emit (events.js:172:7) 
at Socket.<anonymous> (/var/www/soren_api/node_modules/mongodb-core/lib/connection/connection.js:173:49) 
at Socket.g (events.js:260:16) 
at emitOne (events.js:77:13) 
at Socket.emit (events.js:169:7) 
at connectErrorNT (net.js:998:8) 
at nextTickCallbackWith2Args (node.js:441:9) 
at process._tickCallback (node.js:355:17) 

我用以下方式连接到我的服务器:

mongoose.connect('mongodb://soren_site'); 

那么,有谁能告诉我什么我做错了吗?

mongod输出:

2017-02-12T15:29:21.219+0000 I CONTROL [initandlisten] MongoDB starting : pid=7726 port=27017 dbpath=/data/db 64-bit host=WGJG008 
2017-02-12T15:29:21.219+0000 I CONTROL [initandlisten] db version v3.0.14 
2017-02-12T15:29:21.219+0000 I CONTROL [initandlisten] git version: 08352afcca24bfc145240a0fac9d28b978ab77f3 
2017-02-12T15:29:21.219+0000 I CONTROL [initandlisten] build info: Linux ip-10-30-223-232 3.2.0-4-amd64 #1 SMP Debian 3.2.46-1 x86_64 BOOST_LIB_VERSION=1_49 
2017-02-12T15:29:21.219+0000 I CONTROL [initandlisten] allocator: tcmalloc 
2017-02-12T15:29:21.219+0000 I CONTROL [initandlisten] options: {} 
2017-02-12T15:29:21.243+0000 E NETWORK [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017 
2017-02-12T15:29:21.243+0000 E NETWORK [initandlisten] addr already in use 
2017-02-12T15:29:21.243+0000 I STORAGE [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating 
2017-02-12T15:29:21.244+0000 I CONTROL [initandlisten] dbexit: rc: 100 
+0

哪个OS MongoDB是上运行?你可以通过mongo shell访问它吗? – Astro

+0

@Astro Ive添加了mongod –

+0

@Astro的输出,我可以使用mongo –

回答

1

这看起来像主机名解析问题。

确保您在连接字符串中传递的主机名是可解析的。

而且,如果没有找到,你可能需要条目添加到您的/ etc/hosts文件

希望这有助于