Getting ECONNREFUSED 127.0.0.1:27017

Hello,

I’m using Ubuntu 24.04 and have this error when trying to connect on my mongodb :

Current Mongosh Log ID: 67b5ee0c218ceaf5f3e43268
Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.3.9
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017

I already started my db using :

sudo systemctl restart mongod
sudo systemctl status mongod
● mongod.service - MongoDB Database Server
     Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; preset: enabled)
     Active: active (running) since Wed 2025-02-19 14:34:24 UTC; 160ms ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 910431 (mongod)
     Memory: 2.9M (peak: 3.2M)
        CPU: 21ms
     CGroup: /system.slice/mongod.service
             └─910431 /usr/bin/mongod --config /etc/mongod.conf

and my config seems to be correct :

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
#  engine:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1


# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

my service as well seems to be ok :

[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network-online.target
Wants=network-online.target

[Service]
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
Environment="MONGODB_CONFIG_OVERRIDE_NOFORK=1"
Environment="GLIBC_TUNABLES=glibc.pthread.rseq=0"
ExecStart=/usr/bin/mongod --config /etc/mongod.conf
RuntimeDirectory=mongodb
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false

# Recommended limits for mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings

[Install]
WantedBy=multi-user.target

I’m out of solution and i dont know how to fix that, any clues ?

Thanks in advance !

@Fred_B Are there any relevant entries in your mongod.log file, in particular, an indication that it successfullys tarted to listen on port 27017?

I can’t see anything obviously wrong here either.

Thx for you quick reply, well the only log i found was using

 sudo journalctl -xeu mongod --no-pager | tail -n 50

with multiple restart during my test

 Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ The unit mongod.service has successfully entered the 'dead' state.
Feb 19 15:01:21 ubuntu-s-1vcpu-2gb-fra1-01 systemd[1]: Stopped mongod.service - MongoDB Database Server.
░░ Subject: A stop job for unit mongod.service has finished
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A stop job for unit mongod.service has finished.
░░
░░ The job identifier is 58272 and the job result is done.
Feb 19 15:01:21 ubuntu-s-1vcpu-2gb-fra1-01 systemd[1]: Started mongod.service - MongoDB Database Server.
░░ Subject: A start job for unit mongod.service has finished successfully
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░
░░ A start job for unit mongod.service has finished successfully.

And my /var/log/mongodb/mongod.log dont seems to be created, so i created it manually with the propery access for mongodb but i get nothing from it.

I’m really out of ideas…

@Fred_B I think that’s a helpful sign, it narrows down things by making it likely that there’s something wrong indeed on the service setup side of things.

If you run `` /usr/bin/mongod --config /etc/mongod.conf` manually while the service is stopped, do you see any issues/a log file being created?

Manual launch of mongodb ? Well it does not do anything, just got a blank line :

root@ubuntu-s-1vcpu-2gb-fra1-01:~# sudo /usr/bin/mongod --config /etc/mongod.conf
^C

Then i CTRL C it

@Fred_B And it doesn’t write to /var/log/mongodb/mongod.log either? It should definitely do at least that