0

This is more of a general question about how MongoDB works.

But I've been using MongoDB for a while and everything seems to be working for me. The part that currently confuses me, though, is that when I visit the directory where the MongoDB data is saved (I'm using the default data/db) the directory is empty. The data is being persisted, I'm just confused - why does the directory appears empty on my computer?

I'm on Windows, if that's worth anything.

Austin Brown
  • 830
  • 12
  • 24

2 Answers2

2

You can execute :

  db.serverCmdLineOpts().parsed.storage.dbPath

from inside the mongo process and find what the dbPath startup parameter show to find where your data is saved

or alternatively check from the config file in windows:

 <install directory>/bin/mongod.cfg 
R2D2
  • 9,410
  • 2
  • 12
  • 28
  • Hmm. That's an interesting command, looks useful for learning more. Unfortunately there weren't any parameters named `dbPath` in the output. – Austin Brown Mar 04 '21 at 01:13
  • my mistake , check again my answer , the correct command is db.serverCmdLineOpts() – R2D2 Mar 04 '21 at 07:34
  • btw just found this question is already answered in details here: https://stackoverflow.com/questions/7247474/how-can-i-tell-where-mongodb-is-storing-data-its-not-in-the-default-data-db – R2D2 Mar 04 '21 at 07:39
1

dbPath can be confusing.

When you run mongod without --dbpath option or unset it in config file then it defaults to \data\db

However, when you use the default config files which comes along the installation then the dpPath is different (I don't remember by heart which). So you should really check path with db.serverCmdLineOpts() as suggested by R2D2

I know, for Linux the default dbPath is /data/db but the pre-installed config file /etc/mongod.conf has set /var/lib/mongo

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110