Vagrant setup properly but Mongod not finding /data/db

Was able to setup Vagrant successfully and verified both database and infrastructure running and syncing. However, when attempting 1st lab - starting mongod, it is not finding the /data/db directory. seems to be starting okay, but get
"exception in initAndListen: 29 Data directory /data/db not found., terminating

Seems like MongoDB is there, but config is differing from the default. Course did not provide a config file to run or any specific options to use in the setup. Is there something I missed
Anyone else run into this?? Appreciate any insight.

How did y0u start mongod?
What params you passed?
If you ran just mongod without any options it will try to bring up mongod on port 27017 and default path /data/db
Since /data/db does not exist it is failing

Your lab would have mentioned what path to use
Something like /home/vagrant/M310

If you still want mongod to work on default path create the directory /data/db first

Here is the lab-problem instruction below…


In this first homework exercise we would like for you to demonstrate that you are able to get a standalone server up and running with authentication enabled.

Let’s bring up our Vagrant machine, available as part of the lesson handouts.

cd m310-vagrant-env vagrant up $ vagrant ssh database


For this exercise we want you to perform the following set of tasks:

  • Launch mongod with no authentication enabled
  • Create user alice with password secret on admin database and role root
  • Relaunch mongod with authentication enabled
  • Run command
    db.runCommand({getParameter: 1, authenticationMechanisms: 1})

In the Vagrant install, it references a "shared"directory that gets created and that it states - and I used to verify that a sync is properly setup between database and infrastructure. It would seem odd to me, but perhaps is the case that the db directory should be set to that.

“You’ll notice that in spinning up these VMs a new shared folder was created. This folder is automatically synced with both of your VMs. You’ll use this as a mechanism to bring different files and scripts into your virtual environments”.

Sorry, in the paste of the lab display, it dropped the “return” in the commands… should read…
cd m310-vagrant-env
vagrant up
$ vagrant ssh database

You did not clarify how you attempted to start mongod
If you have issued just mongod it will not work unless /data/db directory exists

This is an advanced course.You would have learnt various methods to start mongod in basic cluster admin course(command line,with config)

You can use any dir where read/write privs are there if nothing is mentioned in your lab
Infact you can complete this on any other VM like M103 or local mongod instance
Need not be database VM
If you want to do it on database VM only then use an appropriate dbpath dir where mongod has read/write privileges

I was able to figure out options to start mongod and complete this lab/homework successfully

I initially tried to start mongod with no options as the instructor did in the lecture. Realized with the error return that the /data/db directory did not exist for the default port.

Do understand this is an advanced course, and I have learned the various methods. Do find it strange that for all other labs in this chapter, the do provide specific options for starting mongod. Fortunately, was from looking at these that figured out my solution. In all cases they specify ports which are very different from the 27000 range. I had attempted start ups in the normal port ranges which have seen even in all prior MongoDB courses., but with no success.

Recommend to others to look at all the labs before even starting with the first.

Thank you for your assistance, appreciate it!

1 Like