MongoDB: Failed to connect to reason: Connection refused

MongoDB failed to connect reason Connection refused error
Error Message:
# mongo
MongoDB shell version v3.6.8
connecting to: mongodb://
2022-04-08T13:16:33.543-0700 W NETWORK  [thread1] Failed to connect to, in(checking socket for error after poll), reason: Connection refused
2022-04-08T13:16:33.544-0700 E QUERY    [thread1] Error: couldn't connect to server, connection attempt failed :
exception: connect failed

The most common reason for Connection refused error when running the mongo command is that your mongod server is not running.


Run the mongod command to start the mongoDB server and then try the mongo command,

# mongod
2022-04-08T13:15:56.482-0700 I CONTROL  [initandlisten] MongoDB starting : pid=5171 port=27017 dbpath=/data/db 64-bit host=b2391b608026
2022-04-08T13:15:56.482-0700 I CONTROL  [initandlisten] db version v3.6.8
2022-04-08T13:15:56.482-0700 I CONTROL  [initandlisten] git version: 8e540c0b6db93ce994cc548f000900bdc740f80a
2022-04-08T13:15:56.482-0700 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.1.1f  31 Mar 2020
2022-04-08T13:36:31.974-0700 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/'
2022-04-08T13:36:31.975-0700 I NETWORK  [initandlisten] waiting for connections on port 27017
# mongo
MongoDB shell version v3.6.8
connecting to: mongodb://
Implicit session: session { "id" : UUID("0e4156ce-070c-49a5-8bb9-fd43aae91bb1") }
MongoDB server version: 3.6.8
Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap