Failed to open "/data/log/mongodb.log"

Hi, I’m trying to do Chapter 1: The Mongod Lab - Launching Mongod. When I run my command the result is:

In other post which is closed recommend review the permissions, change it and rerun the command.

The permissions are:

image

The sudo command:

sudo chmod 777 log

After rerun the command I get the same result: Failed to open “/data/log/mongodb.log”

What can I do?

Thanks in advance

What command?

Which folder/directory?

Hi the command is:

mongod --dbpath /data/db --logpath /data/log/mongodb.log --port 27000 --bind_ip localhost,"192.168.103.100"

The folder is log and its permissions are:

image

Run a few steps:

  • rm -r /data/{db,log}
  • sudo chown vagrant:vagrant /data
  • mkdir -p /data/{db,log}
  • mongod --dbpath /data/db --logpath /data/log/mongodb.log --port 27000 --bind_ip localhost,192.168.103.100

Hi, I have the same result. I run these commands:

cd data
ls
rm -r db
rm -r log
sudo chown vagrant:vagrant /data
mkdir -p db
mkdir -p log
mongod --dbpath /data/db --logpath /data/log/mongodb.log --port 27000 --bind_ip localhost,192.168.103.100

cd data and cd /data are two different locations.

Suggest you don’t cd to any directory. Just run the steps exactly as given in my post.

Hi @luisjmlky,

You are getting this error because of the permission issue.

Please run this command for changing the ownership of the directory.

sudo chown vagrant:vagrant /data/log/

Hope it helps!

If you have any other query then please feel free to get back to us.

Thanks,
Shubham Ranjan
Curriculum Support Engineer

Thank you @007_jb, @Shubham_Ranjan