Creation of MongoDB Service

  1. Go to the location where MongoDB is installed. Refer to the Path set in the PATH environment variable. For e.g., C:\Program Files\MongoDB
  2. Go to Server\8.0\bin folder. for e.g., C:\Program Files\MongoDB\Server\8.0\bin
  3. Locate the file named mongod.cfg and copy the file.
    Figure 1. Creation of MongoDB Service
    A screenshot of a computer Description automatically generated
  4. Go to the mongo folder that was customized earlier. Inside the directory data, go to the config folder. Paste the mongod.cfg file here.
    Figure 2. Creation of MongoDB service (Cont.)
    A screenshot of a computer Description automatically generated
  5. Open the file mongod.cfg (preferably in Notepad++ or Sublime) and follow the following steps:
    Note:
    While editing the file, maintaining indentation in the file is very important.
    1. In the storage header, change the following field:
      • dbPath: Add path till mongo\data\database.
    2. In the systemLog, change the following field:

      • path: Add path of mongo\data\log\mongod.log.
      Note:
      Folder mongo\data\log doesn’t have Mongod.log. This will be created automatically when mongoDB service is created.
    3. In the net, change the following fields:

      • port: Enter the port for the installation of MongoDB.
      • bindIpAll: true.
      • User needs to change bindIp to bindIpAll
        Figure 3. Creation of MongoDB service (Cont.)
        A screenshot of a computer Description automatically generated
    4. Save the changes made in the file mongod.cfg.

    5. Open the Command Prompt as Administrator and run the following command:

      Note:
      Please make sure to provide correct path for config.
      mongod –config “<path of the mongoDB folder you
      created\mongo\data\config\mongod.cfg>" --install --serviceName "MongoDBMongoDB"
      For e.g. mongod --config "C:\mongo\data\config\mongod.cfg" --install --serviceName "MongoDBMongoDB"
    6. MongoDB service with the name MongoDB will be created.