Change the Default DB Path

Hello Fellows,
I am running mongod configurations on windows 7 and so far everything worked fine, until I got to change default DB path, using /var/mongodb/db.
The default storage data/db worked correctly.
My question is, how do I create and change owner of the above directory in windows 7 (cmd)?
Since sudo is not windows command, how do I go about it?
Validate_lab_configuration_file tells me the following message:
2019-05-19T18:13:26.320+0000 I STORAGE [initandlisten] exception in initAndListen: NonExi
stentPath: Data directory /var/mongodb/db not found., terminating
Any ideas to help me move on?


You must follow Windows instructions when running Windows. Path like /var/… are for unix like system.

My system is Windows 10 but Vagrant works as an Ubuntu emulator, right?

I’m asking this because if it’s possible to configure Vagrant as a Windows system I’d prefer it by far, I have no idea about Linux (neither about Windows CMD, but at least it’s Windows).

Using what you know about the configuration file and Linux user groups...

I don’t even know what Linux user groups are.

OK, after getting some help from a keen-on-Linux-friend:

Entering /var:
vagrant@m103:~$ cd /var

Creating /mongodb:
vagrant@m103:/var$ sudo mkdir mongodb

Entering /mongodb to create /db and change the owner:
vagrant@m103:/var$ cd mongodb
vagrant@m103:/var/mongodb$ sudo mkdir db
vagrant@m103:/var/mongodb$ cd db
vagrant@m103:/var/mongodb/db$ sudo chown vagrant:vagrant /var/mongodb/db

Checking that it worked:
vagrant@m103:/var/mongodb/db$ cd ..
vagrant@m103:/var/mongodb$ ls -la

total 12
drwxr-xr-x 3 root root 4096 Jun 25 08:40 .
drwxr-xr-x 16 root root 4096 Jun 25 08:23 …
drwxr-xr-x 2 vagrant vagrant 4096 Jun 25 08:40 db

Is this OK?


Now I’m at this point:

Once your mongod is safely stopped, you can launch it again with your new config file.

mongod --config mongod.conf

But I get an error:
Error reading config file: No such file or directory

The file is where I left it for the last lab…

Run pwd to tell us where you are and run ls to show us the files you have.

@steevej-1495 my set up is exactly the same

vagrant@m103:/data/db$ mongod --config mongod.conf
2019-06-25T12:39:24.971+0000 I CONTROL  [main] log file "/data/mongod.log" exists; moved to "/data/mongod.log.2019-06-25T12-39-24".

heres how my config file looks:

  dbPath: "/var/mongodb/db"
  bindIp: ","
  port: 27000
  destination: file
  path: "/data/mongod.log"
  authorization: enabled


2019-06-25T12:42:32.974+0000 I STORAGE  [conn1] WiredTigerKVEngine shutting down
2019-06-25T12:42:33.069`0000 I STORAGE  [conn1] shutdown: removing fs lock...
2019-06-25T12:42:33.069+0000 I CONTROL  [conn1] now exiting
2019-06-25T12:42:33.069+0000 I CONTROL  [conn1] shutting down with code:0
vagrant@m103:/data/db$ mongod --config mongod.conf
2019-06-25T12:44:45.623+0000 I CONTROL  [main] log file "/data/mongod.log" exists; moved to "/data/mongod.log.2019-06-25T12-44-45"
agrant@m103:/var/mongodb$ mongo admin --port 27000

MongoDB shell version v3.6.12

connecting to: mongodb://

2019-06-25T12:51:18.234+0000 W NETWORK [thread1] Failed to connect to, in(checking socket for error after poll), reason: Connection refused

2019-06-25T12:51:18.235+0000 E QUERY [thread1] Error: couldn't connect to server, connection attempt failed :



exception: connect failed`

Please share mongod.log.

vagrant@m103:~$ pwd
vagrant@m103:~$ ls
vagrant@m103:~$ ls -a
.  ..  .bash_history  .bash_logout  .bashrc  .cache  .dbshell  .mongorc.js  .profile  .ssh  mongod

@Sonali_Mamgain agrant@m103:/data/db$ validate_lab_different_logpath

You need to set logAppend to true.

  dbPath: "/var/mongodb/db"
  bindIp: ","
  port: 27000
  fork: true
  destination: file
  path: "/data/mongod.log"
  logAppend: true
  authorization: enabled

any reason why im still getting error?

@Sonali_Mamgain now lol

vagrant@m103:/data/db$ validate_lab_different_logpath

You need to specify the millisecond threshold for slow operations.


Hi @James_68753,

Please correct the validation script. If you are doing the Lab - Change the Default DB Path, then use the following script:


SUCCESS!!! thank you!

@JavierBlanco, where is your config file?

Please share your log file.