2017-02-12 74 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文件

希望這有助於