Unable to start MongoDB after changing the data directory - mongodb

I have installed with the help of following link: https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-16-04
It was working fine by default. But when I change data directory in /etc/mongod.conf
#From
dbPath: /var/lib/mongodb
#To
dbPath: /media/user/'Mounted Volume'/mongodb_data
I am unable to start MongoDB. Following is the error message
$mongo
MongoDB shell version: 3.2.11
connecting to: test
2017-01-06T00:57:01.472+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2017-01-06T00:57:01.472+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:229:14
#(connect):1:6
exception: connect failed
Following is the status
$ sudo systemctl status mongodb
mongodb.service - High-performance, schema-free document-oriented database
Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset:
Active: failed (Result: exit-code) since Fri 2017-01-06 00:56:40 IST; 7s ago
Process: 5735 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (cod
Main PID: 5735 (code=exited, status=100)
Jan 06 00:56:40 GL552VW systemd[1]: Started High-performance, schema-free docume
Jan 06 00:56:40 GL552VW systemd[1]: mongodb.service: Main process exited, code=e
Jan 06 00:56:40 GL552VW systemd[1]: mongodb.service: Unit entered failed state.
Jan 06 00:56:40 GL552VW systemd[1]: mongodb.service: Failed with result 'exit-co
I am new to MongoDB. Maybe I am missing something very simple.

From the MongoDB config file documentation page
The Linux package init scripts included in the official MongoDB packages depend on specific values for systemLog.path, storage.dbpath, and processManagement.fork. If you modify these settings in the default configuration file, mongod may not start.
So if you modify these properties in the configuration file, you most probably have to write a new init script.

Related

couldn't connect to server 127.0.0.1:27017 while trying to start mongodb

After typing mongo
It is showing
MongoDB shell version v5.0.13
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 :
connect#src/mongo/shell/mongo.js:372:17
#(connect):2:6
exception: connect failed
exiting with code 1
Also, the MongoDB campus showing connect ECONNREFUSED 127.0.0.1:27017
For mongosh
Current Mongosh Log ID: 6341cd406845432d371fc4b3
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.6.0
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017
Mongod Service also not starting
root#jahid:/home/jahid# sudo systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2022-10-09 12:48:22 +06; 9min ago
Docs: https://docs.mongodb.org/manual
Main PID: 28523 (code=exited, status=14)
Oct 09 12:48:21 jahid systemd[1]: Started MongoDB Database Server.
Oct 09 12:48:22 jahid systemd[1]: mongod.service: Main process exited, code=exited, status=14/n/a
Oct 09 12:48:22 jahid systemd[1]: mongod.service: Failed with result 'exit-code'.

Mongodb 4.41 does not start in Ubuntu 20.04

I installed Mongodb 4.4.1 following the documentation of the mongodb site. installation was smooth. But when I am checking the status of the mongod service, I am getting an error as below:
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2020-09-16 22:22:23 IST; 6s ago
Docs: https://docs.mongodb.org/manual
Process: 36655 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, stat> Main PID: 36655 (code=exited, status=14)
Sep 16 22:22:22 Ubuntu-PC systemd[1]: Started MongoDB Database Server.
Sep 16 22:22:23 Ubuntu-PC systemd[1]: mongod.service: Main process
exited, code=exited, s> Sep 16 22:22:23 Ubuntu-PC systemd[1]:
mongod.service: Failed with result 'exit-code'.
Even when I try to open mongo shell typing mongo, I get the following error:
MongoDB shell version v4.4.1 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 : connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6 exception: connect failed exiting with code 1
The service is showing as started and enabled. Pleas help. Where have I done the mistake. Thanks in advance.
Try this:
service mongod stop
systemctl start mongod
To start using MongoDB:
mongo

Unable to start MongoDB server on Ubuntu 20.04

I'm installing the latest MongoDB on Ubuntu 20.04 (Focal Fossa), and it's giving the below error. How can I fix it?
sudo systemctl status mongod
mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2020-08-28 23:40:03 IST; 1min 43s ago
Docs: https://docs.mongodb.org/manual
Main PID: 10901 (code=exited, status=217/USER)
systemd[1]: Started MongoDB Database Server.
systemd[10901]: mongod.service: Failed to determine user credentials: No such process
systemd[10901]: mongod.service: Failed at step USER spawning /usr/bin/mongod: No such process
systemd[1]: mongod.service: Main process exited, code=exited, status=217/USER
systemd[1]: mongod.service: Failed with result 'exit-code'.
systemd[1]: /lib/systemd/system/mongod.service:11: PIDFile= references a path below legacy directory >
Changing ownership of "/var/lib/mongodb" directory worked for me.
Command to change ownership:
sudo chown -R mongodb:mongodb /var/lib/mongodb

MongoDB does´t start, exit code 203

I installed MongoDB on the Ruspberry pi desktop on a VM, then I started it with the following command:
sudo service mongod start
The result of this command is the following:
systemctl list-unit-files --state enabled
mongodb.service enabled
Then when I check the status using
sudo service mongod status
The other issue is that there´s no .sock file in my /tmp folder.
PS: I removed MongoDB and reinstalled it trying to fix the issue but I always get the same problem.
Can anyone help me please?
Thank you in advance.
I get the following error:
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2020-06-08 12:33:17 CEST; 3s ago
Docs: https://docs.mongodb.org/manual
Process: 22168 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=203/EXEC)
Main PID: 22168 (code=exited, status=203/EXEC)
Jun 08 12:33:17 raspberry systemd[1]: Started MongoDB Database Server.
Jun 08 12:33:17 raspberry systemd[22168]: mongod.service: Failed to execute command: Exec format error
Jun 08 12:33:17 raspberry systemd[22168]: mongod.service: Failed at step EXEC spawning /usr/bin/mongod: Exec format error
Jun 08 12:33:17 raspberry systemd[1]: mongod.service: Main process exited, code=exited, status=203/EXEC
Jun 08 12:33:17 raspberry systemd[1]: mongod.service: Failed with result 'exit-code'.```

Not able to give remote access to mongodb server to other systems which are is in same wifi network on ubuntu

When I set bindIp of mongod.conf file as my wifi router's default gateway i.e bindIp:127.0.0.1,198.168.3.1. my MongoDB server stops and I get following error when I check its status.
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset:
Active: failed (Result: exit-code) since Thu 2020-01-23 17:42:38 IST; 1s ago
Docs: https://docs.mongodb.org/manual
Process: 3046 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited
Main PID: 3046 (code=exited, status=48)
Jan 23 17:42:38 sarvahapc systemd[1]: Started MongoDB Database Server.
Jan 23 17:42:38 sarvahapc systemd[1]: mongod.service: Main process exited, code=
Jan 23 17:42:38 sarvahapc systemd[1]: mongod.service: Unit entered failed state.
Jan 23 17:42:38 sarvahapc systemd[1]: mongod.service: Failed with result 'exit-c
lines 1-11/11 (END)
But when I set bindIp: 0.0.0.0 in mongod.conf file my MongoDB server runs smoothly and it allows remote access to my MongoDB server for other systems which are in my wifi network.
I want to give remote access to my MongoDB server to other systems which are in my wifi network. Can anyone help me with this?