Lab - Change the Default DB Path

Hi
I´m trying to make a new dir but can’t see it after dir

vagrant@m103:~ sudo mkdir -p /var/mongodb/db/ vagrant@m103:~ dir
data first_mongod
vagrant@m103:~$

Samir

Can you please tidy up the lines of text so that it’s easier to read

You created /var/mongodb/db/. The command dir from where you are, /home/vagrant as indicated by ~ will list the content of the current directory, /home/vagrant. If you do dir /var/mongodb you will probably see your new directory.

Hi @Samir_Talic_39646,

sudo mkdir -p /var/mongodb/db/ 

This command will create the var/mongodb/db/ directory in the root directory and not in your current working directory if it’s not already root. The “/” tells the mkdir command to create the directory in the root. You can check the existence of this directory by running the commands mentioned below.

cd /

This will take you to the root directory

dir

Now, you should be able to see the var directory listed here.

Hope it helps!

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

Happy Learning :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Support Engineer

trying to copy my conf file from shared to /var/mongod/db/ but get error

vagrant@m103:~ cd /shared/ vagrant@m103:/shared ls
mongod.conf
vagrant@m103:/shared$ cp mongod.conf /var/mongod/db/
cp: cannot create regular file ‘/var/mongod/db/’: No such file or directory
vagrant@m103:/shared$ cd …
vagrant@m103:/ dir bin data dev home initrd.img.old lib64 media opt root sbin srv tmp vagrant vmlinuz boot dataset etc initrd.img lib lost+found mnt proc run shared sys usr var vmlinuz.old vagrant@m103:/ dir var
backups cache chef crash lib local lock log m103 mail mongodb opt run spool tmp
vagrant@m103:/ dir mongodb dir: cannot access mongodb: No such file or directory vagrant@m103:/ dir /var/mongodb/
db

Samir

You have to create the directory before trying to copy a file into it.

I think it is issue with ownership/permissions

Samir_Talic_39646

Can you cd /var/mongodb
ls -ld
See who is the owner of the directory
Most likely it is root.It should be vagrant
Run this and it should work

sudo chown vagrant:vagrant /var/mongodb/db

Hi @Samir_Talic_39646,

This is the directory that you have in your system.

/var/mongodb/db

And you are trying to copy the mongod.conf file into this directory which does not exist.

/var/mongod/db/

Change the mongod in your command to mongodb and you are good to go.

Hope it helps!

Thanks,
Shubham Ranjan
Curriculum Support Engineer