MongoDB server won't start - mongodb

I just installed Arch Linux today. I'm setting up my development stack, and I'm stuck with mongodb.
I have followed this wiki when installing:
https://wiki.archlinux.org/index.php/MongoDB#Installing_MongoDB
When I try to get into mongo console, I get this:
jan#arch:~$ mongo
MongoDB shell version: 2.4.5
connecting to: test
Tue Jul 9 19:38:13.365 JavaScript execution failed: Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112
exception: connect failed
jan#arch:~$
What am I missing here?
EDIT: I figured out when I run mongod directly from terminal, it starts server fine. However the systemctl start mongodb doesn't start it.

Okay, I've figured it out by scanning journalctl output:
ul 09 19:49:33 arch mongod[1122]: all output going to: /var/log/mongodb/mongod.log Jul 09 19:49:33 arch mongod[1122]: can't open [/var/log/mongodb/mongod.log] for log file: errno:13 Permission denied Jul 09 19:49:33 arch mongod[1122]: Bad logpath value: "/var/log/mongodb/mongod.log"; terminating.
So I searched for user that might be utilized by mongodb:
jan#arch:~$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
...
mongodb:x:998:2::/var/lib/mongodb:/bin/bash
And chowned required folders:
jan#arch:~$ sudo chown -R mongodb:x /var/log/mongodb/
jan#arch:~$ sudo chown -R mongodb:x /var/lib/mongodb/
Started it again:
jan#arch:~$ sudo systemctl start mongodb
It works now.
jan#arch:~$ mongo
MongoDB shell version: 2.4.5
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
>

Related

error starting mongodb with brew start on macOS Catalina 10.15.6

I have tried a few troubleshoots to no avail. They don't seem to match my specific error. I start mongodb with
> brew services start mongodb-community
The terminal says it is succesfully started, but when i
> brew services
to check mongodb's status it says error. No explanation.
But if I open up a new terminal and run mongo, I do however get a more detailed error.
> connecting to: mongodb://127.0.0.1:27017/?
> compressors=disabled&gssapiServiceName=mongodb
> Error: couldn't connect to server 127.0.0.1:27017, connection
> attempt failed: SocketException: Error connecting to
> 127.0.0.1:27017 :: caused by :: Connection refused :
I have found a solution to this problem. The socket exception error is apparently being thrown because the root owns the
/tmp/mongodb-27017.sock
solution
sudo rm -rf /tmp/mongodb-27017.sock
re start mongodb with
brew services start mongodb-community#4.4
it will create a new
/tmp/mongodb-27017.sock
which is owned by user. You can check by
ls -lsah /tmp/mongodb-27017.sock
my output was then
0 srwx------ 1 userName wheel 0B Apr 8 12:05 /tmp/mongodb-27017.sock
where username was previously root.
my solution was found here
https://stackoverflow.com/a/62196227/15311479

Not able to run mongodb version 4.0 on my local machine

Getting this error when I try to run command mongo:
MongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017
2018-07-24T13:08:13.968+0800 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
After run this command sudo service mongod status Its giving me output something like this :
mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: core-dump) since Sel 2018-07-24 13:18:18 +08; 45s ago
Docs: https://docs.mongodb.org/manual
Process: 18153 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=dumped, signal=ABRT)
Main PID: 18153 (code=dumped, signal=ABRT)
root#him: systemd[1]: Started MongoDB Database Server.
root#him: mongod[18153]: 2018-07-24T13:18:18.777+0800 I CONTROL [main] Automatically disabling TLS 1.0, to f
root#him: mongod.service: Main process exited, code=dumped, status=6/ABRT
root#him: mongod.service: Unit entered failed state.
root#him: mongod.service: Failed with result 'core-dump'.
The data files are created under root not the mongodb user when you run from the terminal.
You need to give permissions:
cd /var/lib/mongodb
sudo chown -R mongodb:mongodb *
Hope this helps.
I had the same error, maybe because of ubuntu upgrade from 18.04 to 20.04. Could not start mongod manually, the reason was absence of /data/db and its permissions. Then mongod would start manually but still errorring on mongodb.service. At the end reinstalling mongodb worked. It was a new install so did not care about backups.
$ sudo apt remove mongodb mongo-tools mongodb-clients mongodb-server mongodb-server-core
$ sudo apt autoremove
$ sudo rm -rf /var/lib/mongodb/
$ sudo apt install mongodb

unable to connect to mongodb on localhost

I have installed MongoDB:
user#user-workshop:~$ sudo service mongodb restart
stop: Unknown instance:
mongodb start/running, process 7980
user#user-workshop:~$ mongo
MongoDB shell version: 2.0.4
connecting to: test
Mon Mar 3 21:43:33 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
user#user-workshop:~$
but as you can see, I'm unable to connect to it. What can I do about it?
Try running these commands:
rm /data/db/mongod.lock
mongod --dbpath /data/db --repair
mongod --dbpath /data/db
For more details read: mongodb manual

fail to start mongodb-linux-2.4.1 on Ubuntu 12.04

I have downloaded the mongodb-linux-2.4.1 tarball. Then I untar it. go to mongodb-linux-2.4.1/bin folder and start it by
./mongo
Then I got:
li#li-HP:~/Tools/mongodb-linux-x86_64-2.4.1/bin$ ./mongo
MongoDB shell version: 2.4.1
connecting to: test
Fri Mar 29 19:29:47.958 JavaScript execution failed: Error: couldn't connect to
server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112
exception: connect failed
Any suggestion?
./mongo just run mongodb client
./mongod run mongodb server

mongo displays error on MAMP

I have followed this after installing Mongo on Mac.
On php.ini shows mongo details.
mongo
MongoDB Support enabled
Version 1.0.11
Directive Local Value Master Value
mongo.allow_empty_keys 0 0
mongo.allow_persistent 1 1
mongo.auto_reconnect 1 1
mongo.chunk_size 262144 262144
mongo.cmd $ $
mongo.default_host localhost localhost
mongo.default_port 27017 27017
mongo.long_as_object 0 0
mongo.native_long 0 0
mongo.utf8 1 1
But when I type mongo on a terminal it displays the following error.
sokada-macbook:bin sokada$ mongo
MongoDB shell version: 2.0.6
connecting to: test
Thu Jun 14 21:54:47 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
I thank you in advance to solve this problem.
I needed to run the following in the terminal.
sudo mkdir -p /data/db
sudo chown `id -u` /data/db
Then I run mongo and give the following.
sokada-macbook:~ sokada$ mongo
MongoDB shell version: 2.0.6
connecting to: test
>
It looks like you have successfully installed the Mongo support for PHP, but haven't started the actual mongod server yet.
In the tutorial you followed, that would be Step 4. Create Startup Routines for MAMP.