Lab - Change DB Path

I have updated the db path in my yaml file and successfully launched:

vagrant@m103:~$ mongod -f /shared/chapter1
2018-11-18T21:28:14.455+0000 I CONTROL [initandlisten] MongoDB starting : pid=7381 port=27000 dbpath=var/mongodb/db 64-bit host=m103
2018-11-18T21:28:14.456+0000 I CONTROL [initandlisten] options: { config: “/shared/chapter1”, net: { bindIp: “127.0.0.1,192.168.103.100”, port: 27000 }, security: { authorization: “enabled” }, storage: { dbPath: “var/mongodb/db” } }
2018-11-18T21:29:23.875+0000 I NETWORK [conn7] end connection 127.0.0.1:58331 (1 connection now open)
2018-11-18T21:29:23.875+0000 I NETWORK [conn6] end connection 127.0.0.1:58329 (0 connections now open)

I have created the user per request and then ran the validate script. I keep getting:
vagrant@m103:~$ validate_lab_change_dbpath
You need to specify the dbPath as /var/mongodb/db.

Yet, the runtime above clearly states that my path is var/mongodb/db.

Not sure what I missed.

You mentioned yourself. Its easy to miss the / in front of it but it makes alot of difference in terminal shell.

The dbPath expected: “/var/mongodb/db”

It begins with slash.

Kanika

1 Like

Could somebody tell where to create the folders? I have literally duplicated those everywhere (in m103, in shared, in c:, etc…) but still mongod can’t find them. I think I am creating them in the wrong places. Anybody help? I am in Windows 10. @Kanika

1 Like

Hi maulberto3,

You need to create these directories in vagrant.

  • Go to your vagrant env directory which you must have downloaded:

    m103-vagrant-env$ vagrant up
    m103-vagrant-env$ vagrant ssh
    vagrant@m103:~$ _
    

“vagrant@m103” means you are in vagrant machine now.

You need to create the directory using: (correcting mkdir command, we need to use sudo)

  sudo mkdir -p /var/mongodb/db

MongoDB will be able to find those directories through mongod. You need to telll mongod the dbPath you are using, there are 2 ways either in Configuration file or through command line:

  1. Configuration File:

    storage:
     dbPath: /var/mongodb/db/
    
  2. Command Line:

    mongod --dbPath /var/mongodb/db 
    

Hope it helps!

Kanika

1 Like

It says permission denied. I think I need to use chown. Any hint?

Edit: Please use sudo while creating directory /var/mongodb/db.

Please change the permission on /var/mongodb/db

  sudo chown vagrant:vagrant /var/mongodb/db

If that does not solve the problem, please share the exact message you see and commands you are using.

Kanika

The problem is that /var is owned by root and must stay own by root.

The first step is to create /var/mongodb if it does not exists. This has to be done with sudo:

sudo mkdir /var/mongodb

Then you have to change owner and group of /var/mongodb with:

sudo chown vagrant:vagrant /var/mongodb

You are then good to go and create without sudo’ing the rest of the directories.

1 Like

Thanks steevej-1495 for the correction.

@Kanika and @steevej-1495 definitely helped. I also think I need to up me Linux because I want to approve this course and the MongoDB 4.0 other one (it uses Vagrant too, if I’m not mistaken). Thanks a lot.