I’m installing MongoDB on a Raspberry Pi 5 using Ubuntu Server 24.04 LTS. I tried obtaining an ISO for 22.04 for the Raspberry Pi 5, but I was unable to locate one. Because of this, I am trying to do some workaround to get it to function. I realize now that I may have had a completely functional MongoDB instance running and thought it was broken, which led to me factory resetting it.
After much research, I was finally able to get a Mongod to function and start (which is where I thought there was an error since I don’t remember it starting and not being able to do any command within Mongod), but I wasn’t able to connect to the instance using Mongosh after it was launched/started.
When running “mongosh” on the Raspberry Pi, I am given the error:
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.6
MongoServerSelectionError: Server selection timed out after 2000 ms
I know this may not be much information to go on, but I’ve got no idea what else to include to make it more helpful/useful for you to provide better assistance.
I started the DB when I woke up, and this is the log of the DB starting. To get out of it, I just use control z to be able to type commands of any sort. After it starts, I am unable to use any commands, whether it’s shell or MongoDB commands. If I close out the connection from Putty or CMD and try Mongosh, I get the same error. (See log file, first error showed)
If I try starting with systemctl I get the following (See log file, second error showed)
Hi @Joe_Swanson and welcome to the community!
Can you check if you have the right permission in the data directory and for the /tmp/mongodb-27017.sock file?
I do not have it resolved. I’m still unable to connect to it locally, I haven’t tried connecting to it remotely as I assume it’ll not work if locally won’t either.
I also realized I didn’t mention that MongoDB had access to /data/db while it didn’t have access to /tmp/mongodb-27017.sock
I changed ownership of /tmp/mongodb-27017.sock to MongoDB and applied chmod 777 to it as well.
Output of “ls -l /tmp/mongodb-27017.sock”
srwxrwxrwx 1 mongodb mongodb 0 Jun 4 18:42 /tmp/mongodb-27017.sock
So I lied. I did manage to get it working by doing mongod and then opening another SSH and doing “mongosh,” which was a big facepalm moment. I assumed Ubuntu servers worked a bit differently than ones with desktop environments. That leads me to another question:
How do I prevent the need to remove the .sock file after a reboot, and how do I troubleshoot systemctl?
× mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; preset: enabled)
Active: failed (Result: exit-code) since Wed 2024-06-05 05:50:02 CDT; 1s ago
Duration: 69ms
Docs: https://docs.mongodb.org/manual
Process: 1398 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=14)
Main PID: 1398 (code=exited, status=14)
CPU: 68ms
Jun 05 05:50:02 ubuntu systemd[1]: Started mongod.service - MongoDB Database Server.
Jun 05 05:50:02 ubuntu mongod[1398]: {"t":{"$date":"2024-06-05T10:50:02.242Z"},"s":"I", "c":"CONTROL", "id":748>
Jun 05 05:50:02 ubuntu systemd[1]: mongod.service: Main process exited, code=exited, status=14/n/a
Jun 05 05:50:02 ubuntu systemd[1]: mongod.service: Failed with result 'exit-code'.
Hey @Joe_Swanson
Is a little bit strange, because with the startup of the service it should give the correct permissions. So if I understand correctly, after a restart, you find the .sock with the wrong permissions?
or it is regenerated with the wrong permissions?
Regards
I’m not too sure how systemctl works but the sock file is only created when utilizing systemctl, so I’m not sure if mongodb is supposed to generate it or if it’s only there because it’s a requirement of systemctl kind of thing.
I did try the following to see if it made a difference since it seems to have made a difference for others but that didn’t work.
sudo chown `whoami` /tmp/mongodb-27017.sock
I even tried adding sudo in the service file but didn’t work too well as it’d require a password to function and even if I fed it the password within the file it didn’t recognize it.
For the connection timed out issue to use for “testing”/verifying it is working, I needed to have 2 instances running, 1 with mongod and the other with mongosh running and it worked as expected
For the systemctl issue, the below command fixed the issue due to the reason @steevej mentioned
The issue is stemming from the fact I started mongod manually after the installation, this causes the incorrect file permissions for the usage of systemctl to function properly