Unable to start mongodb

2020-06-16 04:13发布

问题:

I'm trying to install mongodb on my window 7 machine. When trying to start it by using the mongod command I get this error. dbpath (\data\db) does not exist. I followed the steps ath the tutorial. All the folders exist C:\mongodb\log, C:\mongodb\data and C:\mongodb\data\db .

回答1:

The default path is c:\data\db. You are trying to use c:\mongodb\data\db.

This means you have to use the option --dbpath c:\mongodb\data\db for mongod command.



回答2:

By default, when we start the mongodb, it looks for the folder /data/db (on Mac/Linux) or C:\data\db (on windows)...however, during the installation it doesn't create this folder, so when when we run mongodb for the first time, it fails with the error that it can't find C:\data\db folder. The solution is to manually create C:\data\db folder and then start mongodb. This error can be totally avoided if the mongodb installer can just give an option to choose this folder path and then create it as part of mongodb installation itself.



回答3:

In windows you might not have permission for your user. And mongo installer could not create it because of lack of Administrative permission for your user.

So in C:\Program Files\MongoDB:

  1. Create a folder named data
  2. Create a folder named db inside the folder data
  3. Now right click on the data folder and choose properties
  4. Click security tab and select your user there
  5. Click the Full control select box
  6. Click ok, ok, ok ...
  7. important! if you don't have the path "C:\Program Files\MongoDB\Server\3.4\bin" set in environment variable, please set it.
  8. Now go to shell and type : mongod --dbpath "C:\Program Files\MongoDB\data\db"

That's it :)



回答4:

Try to use 2 command Prompts (CMD) at the same time.

First CMD, use the command: mongod (or mongod --dbpath C:\mongodb\data)

Second CMD, use the command: mongo

The second will connect in the database. Do not close the first.