Mongodb正在运行但仍然无法连接(Mongodb is running however still cannot connect)

编程入门 行业动态 更新时间:2024-10-28 08:22:18
Mongodb正在运行但仍然无法连接(Mongodb is running however still cannot connect)

这是我运行service mongod status时得到的:

● 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

This is what i get when i run service mongod status:

● 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.

However whenever i run my server

sudo node server.js

I get the following error message:

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)

I connect to my server in the following way:

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

So can anyone tell me what im doing wrong?

output of 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

最满意答案

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

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

此外,如果未找到,您可能需要向/ etc / hosts添加条目

希望这可以帮助

This looks like hostname resolving issue.

Make sure the hostname you pass in connection string is resolvable.

Also, if not found, you may need to add entry to your /etc/hosts

Hope this helps

更多推荐

本文发布于:2023-08-04 05:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1409312.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正在运行   但仍然   Mongodb   running   connect

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!