Question on Lab - Change the Default DB Path

I was able to create the var folder and mongodb and db subsequnetly without having to do any sudo or chown etc. as you can see the screen-shot below. The I did create the config file (cdpath.cfg) there as the second screen shot.But when I ran I am getting an error about ‘nonexistencepath’ as per the last screen shot.
What am I doing wrong?

vagrant@m103:~ ls -l total 12 drwxrwxrwx 2 vagrant vagrant 4096 Feb 17 18:34 data drwxrwxr-x 4 vagrant vagrant 4096 Feb 13 19:27 first_mongod -rw-rw-r-- 1 vagrant vagrant 0 Feb 17 18:01 md.cfg drwxrwxr-x 3 vagrant vagrant 4096 Feb 17 20:55 var vagrant@m103:~ cd var
vagrant@m103:~/var$ cd mongodb
vagrant@m103:~/var/mongodb$ cd db
vagrant@m103:~/var/mongodb/db$ ls -l
total 4
-rw-rw-r-- 1 vagrant vagrant 129 Feb 17 21:08 cdpath.cfg
vagrant@m103:~/var/mongodb/db$

storage:
dbPath: “/var/mongodb/db”
net:
bindIp: “192.168.103.100,localhost”
port: 27000
security:
authorization: enabled


vagrant@m103:~/var/mongodb/db$ mongod --config “cdpath.cfg”
2019-02-17T21:27:47.470+0000 I CONTROL [initandlisten] MongoDB starting : pid=4900 port=27000 dbpath=/var/mongodb/db 64-bit host=m103
2019-02-17T21:27:47.472+0000 I CONTROL [initandlisten] db version v3.6.10
2019-02-17T21:27:47.472+0000 I CONTROL [initandlisten] git version: 3e3ab85bfb98875af3bc6e74eeb945b0719f69c8
2019-02-17T21:27:47.472+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2019-02-17T21:27:47.473+0000 I CONTROL [initandlisten] allocator: tcmalloc
2019-02-17T21:27:47.473+0000 I CONTROL [initandlisten] modules: enterprise
2019-02-17T21:27:47.473+0000 I CONTROL [initandlisten] build environment:
2019-02-17T21:27:47.473+0000 I CONTROL [initandlisten] distmod: ubuntu1404
2019-02-17T21:27:47.474+0000 I CONTROL [initandlisten] distarch: x86_64
2019-02-17T21:27:47.474+0000 I CONTROL [initandlisten] target_arch: x86_64
2019-02-17T21:27:47.474+0000 I CONTROL [initandlisten] options: { config: “cdpath.cfg”, net: { bindIp: “192.168.103.100,localhost”, port: 27000 }, security: { authorization: “enabled” }, storage: { dbPath: “/var/mongodb/db” } }
2019-02-17T21:27:47.476+0000 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory /var/mongodb/db not found., terminating
2019-02-17T21:27:47.477+0000 I CONTROL [initandlisten] now exiting
2019-02-17T21:27:47.477+0000 I CONTROL [initandlisten] shutting down with code:100
vagrant@m103:~/var/mongodb/db$


You get the error message Data directory /var/mongodb/db not found. That is what you specified in your configuration file. But I can see that you created the directory var/mongodb/db while being in the home directory of vagrant which is /home/vagrant. Effectively you have created /home/vagrant/var/mongodb/db.

4 Likes

Thank you. This was helpful I can see that I need to learn more linux.

While with your help I was able to run the mongod with the config file but when I tried to run the validate command as per the lab requirement I am getting another error which probably another linux ignorance is hurting me. Will appreciate any help.
vagrant@m103:~$ validate_lab_change_dbpath
You need to specify the dbPath as /var/mongodb/db.

As steevej-1495 pointed out you created /home/vagrant/var/mongodb/db. While this will work for you. But when you run validate command, it will check for dpPath as /var/mongodb/db. You need to go to root directory and there you will find the var directory already present. Inside this directory create mongodb/db. Here you need to use both sudo and chown commands. Then specify path as /var/mongodb/db.

3 Likes

Thanks Mahesh. How do I go to root directory? I did cd … and it takes me to vagrant@m103:/home

there ls - gives me ubuntu and vagrant directories

use cd one more time. then use ls command you will see var directory

1 Like

Thank you Mahesh. It did get me past this. I am now finding my way to do the rest to finish this lab. Think after this chapter (and its lab etc., is done) I will start learning linux at the same time alongside chapter 3.
Thanks again.
Ashok

Update: I was able to finish the lab with the great help by Mahesh and Steevj

Thank you all.
Ashok

1 Like

Hi Mahesh,
As you have mentioned in your comment I did used Sudo to create “/mongodb/db” directory under root (/var directory), and when I tried to use “chown” I get below error.

And when I tried to connect mongod using config file I get below error

Please help me here as i do not see a way forward and i am new to Linux …
Thanks in Advance !!

Yes Unix/Linux fundamentals
You need sudo to change permissions
Why you are trying to change /var?
Please try this

sudo chown vagrant:vagrant /var/mongodb/db

2 Likes

Thanks alot Ramachandra ,
I was under the impression that if I change the permission of “/var” the child directories will auto inherit.
Have to learn Unix/Linux fundamentals !!
Regards,
Sharad

One need to move to VAR directory first.

cd …
cd …
cd var

  1. Make the directory mongodb/db using from with /var (so beforehand cd /var )

sudo mkdir -p mongodb/db

This creates the subdirectory mongodb and db in one pass.

  1. Change permissions so vagrant owns it, both as the owner and group. You should still be in /var

sudo chown -R vagrant:vagrant mongodb

The -R recursively applies those permissions to the directory mongodb and its subdirectory db .Now check the directory listing.

Thanks to N Mullins

I also experienced problems with an invalid directory path but eventually figured it out (after pretty much creating the new directories all over the server). Given how rarely i use linux on a day to day basis, it was not in any way intuitive to realize that they wanted us to create a “mongodb” directory within the EXISTING root “var” directory. And why would we? This is a mongodb course, not a linux course. I don’t see how spending two hours refreshing on linux contributes anything to my understanding of mongodb, as the product runs on Windows Servers as well.

Hi James_72351,

I agree with you! There are Windows users as well. And we as a team are renewing our courses without the use of Vagrant.

The purpose of vagrant was to ensure a common platform for the learners and to provide all the related tools at one place.

I really appreciate the feedback and we are looking for a solution. Any suggestions are welcome.

Meanwhile, our team is working hard. :slight_smile:

Kanika

Hi Kanika,

Thank you for sharing your insight as well. Perhaps a link to a video demonstrating how to define the directory in vagrant?

Sure. I am thinking more of a link for a short tutorial/steps on Vagrant like:

  • creating directory
  • creating file
  • moving files.

Let me see what can we do in a short time.

Kanika

Adding more here.

I have made this post a while ago, how about adding it as lecture notes?

Kanika