0
votes

when I try to initialize a MongoDB project , it says " 2018-07-28T21:54:34.391+0530 F CONTROL [main] Failed global initialization: BadValue: dbPath requires an absolute file path with Windows services".

If someone knows what is the reason for that, please let me know...

my command is :

C:\"Program Files"\MongoDB\Server\4.0\bin>mongod --directoryperdb --dbpath C:\"Program Files"\MongoDB\Server\4.0\data\db --logpath C:\"Program Files"\MongoDB\Server\4.0\log\mongo.log --logappend --install

when I try to initialize it returns an error like below...

2018-07-28T21:54:34.391+0530 F CONTROL  [main] Failed global initialization: BadValue: dbPath requires an absolute file path with Windows services

my dbpath -> C:\Program Files\MongoDB\Server\4.0\data\db

my logpath -> C:\Program Files\MongoDB\Server\4.0\log\mongo.log

1
I discovered a solution for that error. I entered mongod --remove command and try to initialize using command below.. mongod --directoryperdb --dbpath C:\mongodb\data\db --logpath C:\mongodb\log\mongo.log --logappend --install .It works... - yasiru

1 Answers

0
votes

Have you installed the mongodb? If you haven't done the install, download the mongodb from the link and install it:

https://www.mongodb.com/dr/fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-4.0.0-signed.msi/download

  1. Create the database folder from command prompt

    mkdir c:\mongodb\data\db
    
  2. Create a folder for the log files.

    mkdir c:\mongodb\logs
    
  3. Create a folder for the config files

    mkdir c:\mongodb\config
    
  4. Create a file called mongodb.cfg with the following contents under the config folder c:\mongodb\config.

    port=27017
    dbpath=C:\mongodb\data\db\
    logpath=C:\mongodb\logs\mongod.log
    maxConns=100
    
  5. Start the mongod (for a manual startup. To automate the startup, use step 6 instead)

    "C:\Program Files\MongoDB\Server\4.0\bin\mongod" --directoryperdb --config "C:\mongodb\config\mongodb.cfg" --fork
    
  6. Alternatively define the service

    "C:\Program Files\MongoDB\Server\4.0\bin\mongod" --directoryperdb --config "C:\mongodb\config\mongodb.cfg" --install --serviceName "MongoDB"
     net start MongoDB
    

Now your database in localhost with the port 27017 is running. You can create or use the database in node.js or in your favorite programming language.