So guys, I've been trying to execute MongoDB on my MacBook Pro (OSX 10.15.4) by running
sudo mongod
Then
mongo
but when I run mongo command it returns the following error:
exception in initAndListen: DBPathInUse: Unable to create/open the lock file:
/data/DB/mongod.lock (Read-only file system). Ensure the user executing mongod is the owner
of the lock file and has the appropriate permissions. Also make sure that another mongod
instance is not already running on the /data/db directory, terminating
I already added the Mongo folder to my /etc/paths and created the /data and /db folders using the command mkdir.
There's no lockfile and all the permissions are granted. I also tried to kill the mongo process but I still get the same error.
Any tips?
Thank you.
It seems like you are not owner of mongod.
execute
chown $USER mongo
On recent versions of OSX you are not allowed to create directories in the root even with sudo. I recommend using the --dbpath commandline parameter to locate your database directory in a directory you are entitled to write to. e.g.
mongod --dbpath ${HOME}/data
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I followed the MongoDb Docs to setup my first MongoDb,
When I start MongoDB using the command
C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe
I get the following error
exception in initAndListen: 29 Data directory C:\data\db\ not found., terminating
shutdown: going to close listening sockets...
shutdown: going to flush diaglog...
now exiting
shutting down with code:100
MongoDB needs a folder to store the database. Create a C:\data\db\ directory:
mkdir C:\data\db
and then start MongoDB:
C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe
Sometimes C:\data\db folder already exists due to previous installation. So if for this reason mongod.exe does not work, you may delete all the contents from C:\data\db folder and execute mongod.exeagain.
For macOS users to fix this issue:
You need to go through the following steps:
Create the “db” directory. This is where the Mongo data files will live. You can create the directory in the default location by running:
sudo mkdir -p /data/db
Make sure that the /data/db directory has the right permissions by running:
sudo chown -R `id -un` /data/db
You're all set now and you can run sudo mongod to start the Mongo server.
It's not working if you run only mongod
Source.
Same issue on my Mac (using Brew) solved using:
sudo mongod
For macOS users take care of below issue:
if you installing MongoDB Community on macOS using .tgz Tarball
((Starting with macOS 10.15 Catalina, Apple restricts access to the MongoDB default data directory of /data/db. On macOS 10.15 Catalina, you must use a different data directory, such as /usr/local/var/mongodb.))
you can solve it as the following:
(MacOS Catalina onwards)
Apple created a new Volume in Catalina for security purposes. If you’re on Catalina, you need to create the /data/db folder in System/Volumes/Data.
Use this command:
sudo mkdir -p /System/Volumes/Data/data/db
Then, use this command to give permissions:
sudo chown -R `id -un` /System/Volumes/Data/data/db
this will replace normal
sudo mkdir -p /data/db
Make sure that the /data/db directory has the right permissions by running:
sudo chown -R `id -un` /data/db
once you finish and start mongoDB you can use the following in terminal:
sudo mongod --dbpath /System/Volumes/Data/data/db
To change default db folder C:\data\db in windows, the command is:
--dbpath
For example:
\mongod --dbpath C:\myfolder
Mac Users
Instead of running MongoDB with:
sudo mongod
You can use mongod instead if you:
Locate the data folder of mongodb (usually ~/data)
Add permission to read + write with sudo chmod -R ugo+rw data
If you need to use sudo when running mongodb (sudo mongod), that means you don't have read and write permission on the mongodb data folder
Please take following steps:
As other friends mentioned, you should make a directory first for your database data to be stored. This folder could be something like:
C:\mongo-data
From command line navigate to where you have installed mongodb and where mongod.exe resides. In my case the full path is:
C:\Program Files\MongoDB\Server\3.4\bin
From here run mongod.exe and pass it the path to the folder you created in step one using the flag --dbpath as follows:
mongod.exe --dbpath "C:\mongo-data"
Please Note: If you are on windows it is necessary to use double-quotes ("") in the above to run properly.
In this way you will get something like the following:
2017-06-14T12:45:59.892+0430 I NETWORK [thread1] waiting for connections on port 27017
If you use single quotes (' ') on windows, you will get:
2017-06-14T01:13:45.965-0700 I CONTROL [initandlisten] shutting down with code:100
Hope it helps to resolve the issue.
To run Mongo DB demon with mongod command, you should have a database directory, probably you need to run:
mkdir C:\data\db
Also, MongoDB need to have a write permissions for that directory or it should be run with superuser permissions, like sudo mongod.
I kept getting the following error when I tried to start mongodb (on mac os).
"shutting down with code:100"
I was using the following command:
./mongod --dbpath=~/mongo-data
The fix for me was that I didn't need the "=" sign and this was causing the error. So I did
./mongod --dbpath ~/mongo-data
Just wanted to throw this out there because the error in no way specifies that this is the problem. I almost removed the contents of the ~/mongo-data directory to see if that helped. Glad I remembered that cli args sometimes do not use the "=" sign.
first you have to create data directory where MongoDB stores data. MongoDB’s default data directory path is the absolute path \data\db on the drive from which you start MongoDB.
if you have install in C:/ drive then you have to create data\db directory. for doing this
run command in cmd
C:\>mkdir data\db
To start MongoDB, run mongod.exe.
"C:\Program Files\MongoDB\Server\4.2\bin\mongod.exe" --dbpath="c:\data\db"
The --dbpath option points to your database directory.
Connect to MongoDB.
"C:\Program Files\MongoDB\Server\4.2\bin\mongo.exe"
to check all work good :
show dbs
1.If it shows error (shutting down
with code 100) that means it is not finding the desired
location of file.
1.a If its before macOS Catalina then create directory with
sudo mkdir -p /data/db and give permissions to use it
sudo chown -R id -un /data/db.
1.b if it macOS Catalina onwards then make
sudo mkdir -p /System/Volumes/data/db and give it
permissions
sudo chown -R id -un /System/Volumes/data/db.
2.Starting mongo db brew services run mongodb-community
3.Type mongod or mongod --dbpath /System/Volumes/Data/data/db
4.And if the mongod show error (shutting down with code 48) that
means the port is being already use so you can do two things
4.a Either you change the port of mongod by specifying port
number
mongod --dbpath /System/Volumes/Data/data/db —port 27018.
4.b Or You can kill the process at that port by finding
the process by
sudo lsof -i :27017
and then kill by command
kill -9
5.Repeat the step 2 and 3.
In MacOS:-
If you forgot to give the path of the previously created database while running the mongo server, the above error will appear.
sudo ./mongod --dbpath ../../mongo-data/
Reference
Note :- ./mongod && ../../mongo-data is relative path.
So you can avoid it by configuration in environment variable
Reference
For windows i've got same issue.
The fix was - i need to run command line as administrator.
if you already have the directory, check the dir permissions or try to restart mongo with sudo.
sudo brew services start mongodb
In my case, I got a similar error and it was happening because I had run mongod with the root user and that had created a log file only accessible by the root. I could fix this by changing the ownership from root to the user you normally run mongod from. The log file was in /var/lib/mongodb/journal/
I you are using Virtualbox check your VM.
docker-machine ssh
df -h
Look at dev/sda1 if you do not have any free space this may be due to a large number of images, or containers. you can remove them using "docker rm" and "docker rmi"
This exit code will also be given if you are changing MongoDB versions and the data directory is incompatible, such as with a downgrade. Move the old directory elsewhere, and create a new directory (as per the instructions given in other answers).
Aravind.
It happened with me too because I stopped the MongoDB by the Task Manager.
Creating the C:\data\db folder and starting the MongoDB at C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe worked for me, as cespon suggested, but the MongoDB didn't show any of my Databases previously created.
Then, removing the C:\data\db folder and repairing the installation with the MongoDB installer, I recovered my data and started normally the MongoDB.
(I'm very new with MongoDB, but it helped me solve this problem and recover may previews data).
typed mongod and getting error
Errors:
exception in initAndListen: NonExistentPath: Data directory /data/db not found.,
terminating
shuts down with Code 100
Then try with (create data and db folder with all permission)
mongod --dbpath=/data
use new tab and type mongo.
>use dbs
If still you are facing prob
then you can check for mac catalina: (https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x-tarball/)
for windows: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows-unattended/
I am new to MongoDB. I am trying to install MongoDb 3.0 on Ubuntu 13.0 LTS, which is a VM on Windows 7 Host. I have installed MongoDB successfully (packages etc.), but when I execute the command sudo service mongod start, I get the following error in the "/var/log/mongodb/mongod.log" log file. Can anyone help me understanding this error. There is nothing on internet related to this.
2015-04-23T00:12:00.876-0400 I CONTROL ***** SERVER RESTARTED *****
2015-04-23T00:12:00.931-0400 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2015-04-23T00:12:00.931-0400 I - [initandlisten] Fatal Assertion 28578
2015-04-23T00:12:00.931-0400 I - [initandlisten]
I have fixed this issue myself, by deleting the mongodb-27017.sock file . I ran the service after deleting this file, which worked fine. However, I am still not sure the root cause of the issue. The output of the command ls - lat /tmp/mongodb-27017.sock is now
srwx------ 1 mongodb nogroup 0 Apr 23 06:24 /tmp/mongodb-27017.sock
Alternative to the answer provided by KurioZ7, you can simply set the permissions of the .sock file to the current user:
sudo chown `whoami` /tmp/mongodb-27017.sock
This does the trick for me if I want to run mongod without sudo. If I delete the file like in KurioZ7s answer, I will simply get the same error the next time I restart my machine.
This issue occurs when you use the command
mongod
Before using the command
sudo service mongod start
To fix the issue, either:
Set appropriate permissions on the file:
/tmp/mongodb-27017.sock
OR
Remove the file
/tmp/mongodb-27017.sock
Run
sudo service mongod start && mongod
The most likely cause for this was that the mongod process was at some point started by the root user. The socket file (/tmp/mongodb-27017.sock) was therefore owned by the root user. The mongod process usually runs under its own dedicated user, and that user did not have the permissions to delete that file.
The solution, as you already found out, was to delete it. Then mongodb was able to recreate it with the correct permissions. This should persist after reboot, as long as mongodb is started using the init scripts, or under the correct user account.
$ sudo mongod
it solve problem for me
Change the ownership mongodb-27017.sock file in /tmp directory and start the mongod again.
cd /tmp
sudo chown mongodb:mongodb mongodb-27017.sock
sudo systemctl start mongod
For UNIX-based operating systems, as an alternative to the answer provided by Bastronaut, you could also specify the .sock file to be saved to a folder over which mongod has full user rights (corresponding to the way you are running mongod), that way mongod will also be able to remove the .sock file upon shutdown. The default folder to which the .sock file is saved is '/tmp'. To specify another folder, use a custom mongodb configuration file, for instance 'mongodb.conf', and add the following to it:
net:
unixDomainSocket:
pathPrefix: "anotherFolder"
After which you can run mongod with the command:
$ mongod --config /path/to/mongodb.conf
You can read the documentation on: https://docs.mongodb.org/manual/reference/configuration-options/#net.unixDomainSocket.pathPrefix
Manually restarting mongod service after restart fixed the problem.
Long-term solution was to add static host name, instead of ip address 'net' part of mongod.conf file (I suspect the problem is that ip address is not yet given to server, when mongod servis starts).
If you are having this problem using docker, refer to this question:
MongoDB docker container “Failed to unlink socket file”
I have installed MongoDB on a Ubuntu server like is indicated in the docs http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/. Then, I have modified the configuration file /etc/mongod.conf for, later, run a mongod service.
MongoDB runs correctly if I execute:
sudo mongod -f /etc/mongod.conf
But MongoDB stops if I execute:
sudo service mongod start
In the config file /etc/mongod.conf I changed only this:
dbpath=/data/db
logpath=/root/logs/mongod.log
port=20000
With this configuration, the log file is not created too.
If I don't modify the previous values indicated, the service starts correctly. The default values are:
dbpath=/var/lib/mongodb
logpath=/var/log/mongodb/mongod.log
port = 27017
Because the log file is not created with the custom configuration, I have only changed the dbpath for see the error:
[initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?
I tried to run the following commands but without success:
sudo chown -R `id -u` /data/db
sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
Stack:
Ubuntu 14.10
MongoDB 2.6.5
We must make all the directories/files owned by mongod user. For this:
sudo chown -R mongodb:mongodb /data/db
I found a special case where the use of symlinks appears to fail:
Using a standard enterprise install of mongodb except I changed the /var/lib/mongodb to a symlink as I wanted to use an XFS filesystem for my database folder and a third filesystem for the log folder.
$sudo systemctl start mongod (fails with a message no permission to write to mongodb.log).. but it succceded if I started with the same configuration file:
.. as the owner of the external drives (ziggy) I was able to start $mongod --config /etc/mongodb.conf --fork
I eventually discovered that .. the symlinks pointed to a different filesystem and the mongodb (user) did not have permission to browse the folder that the symlink referred. Both the symlinks and the folders the symlinks referred had expansive rights to the mongod user so it made no sense?
I have installed mongodb using macports. I can run mongod from the terminal with
sudo mongod --dbpath /opt/local/var/db/mongodb
When I try to run it with:
sudo port load mongodb
mongod fails to start. The log file shows repeated attempts to start, each of them including the message
info preallocateIsFaster couldn't run due to: couldn't open file /opt/local/var/db/mongodb/journal/tempLatencyTest for writing errno:13 Permission denied; returning false
There is no such file, but the directory exists. It is owned by root with group _mongo. Changing its ownership to _mongo resulted in other problems. I also tried
mongod --repair
and although that had fixed a problem with the lock file it isn't fixing this one. Help appreciated.