Jago
Jago

Reputation: 2935

Configuring MongoDB on Windows

I am trying to set up MongoDB on Windows, and the online docs seem far from accurate.

Under "Configure a Windows Service" part, step 1 mentions to create a config file. Then it mentions to fill in the file with a line in the format logpath="X:\path\mongo.log". However, following the link, the config file is said to be in YAML format, which renders the previous line unreadable in YAML.

I have created a basic mongodb.cfg(.cfg or .conf??) file:

systemLog:
   destination: file
   path: "P:\\Servers\\MongoDB\\logs\\mongodb.log"
   quiet: true
   logAppend: true
storage:
   dbPath: "P:\\Servers\\MongoDB\\data"
   journal:
      enabled: true
net:
   bindIp: 127.0.0.1
   port: 27017

However when I start mongod --config P:\Servers\MongoDB\mongodb.cfg, the service just won't give any output at all, and just hangs.

If I remove the dbPath line, it will just close itself with no message at all.

I have also tried to leave the mongodb.cfg file just like this:

logpath="P:\Servers\MongoDB\logs\mongodb.log"
dbpath="P:\Servers\MongoDB\data"

But execution aborts complaining about any of the 2 paths, even tho they exist. Tried with single backslashes and with escaped backslashes (\\) with no success.

The only way the service works and listens for connections is to manually pass --dbpath only, and ignore any config file and logpath at all. Obviously this is not serious, as I need to keep track of the logs and also might need to change config parameters at some later point.

This is nuts... Am I missing something very basic or this docs are a real mess?

Upvotes: 14

Views: 47716

Answers (7)

A. L.
A. L.

Reputation: 761

For those who installed via *.msi installer and wondering where is .conf file located. Run 'services.msc' and check properties of mongodb service runnable file.

there is a 'Path to executable' like:

"C:\Program Files\MongoDB\Server\6.0\bin\mongod.exe" --config    "C:\Program Files\MongoDB\Server\6.0\bin\mongod.cfg" --service

so the config file is:

C:\Program Files\MongoDB\Server\6.0\bin\mongod.cfg

Upvotes: 7

Vipul Chaudhary
Vipul Chaudhary

Reputation: 51

For window user it's stored here,

C:\Program Files\MongoDB\Server\6.0\bin

if you are not able to find this, then verify that is your service running or not!

Upvotes: 0

Ivan Shesterkin
Ivan Shesterkin

Reputation: 21

You can find logs with reasons why it's not working in log file. In your case, read P:\Servers\MongoDB\logs\mongodb.log file.

Upvotes: 0

devman81
devman81

Reputation: 767

Bit late but I had the exact same issue today. If you use forward slashes for your paths within the config file it works fine.

systemLog: destination: file logAppend: true path: "e:/mongo_data/3.6/mongo.log" storage: dbPath: "e:/mongo_data/3.6/db" engine: "wiredTiger"

Upvotes: 2

ravi
ravi

Reputation: 11

check if you have any file in data\db path. Please remove all those files and try to restart. I exactly used your config file and able to start the service successfully with bindip and port

Upvotes: 1

wbdarby
wbdarby

Reputation: 1149

Here is my simple test MongoDB Config file for Windows. Note that I had to have 2 spaces before each property, e.g., path. When I had 3 spaces I got an error at startup.

I start the server with: mongod --config c:\tools\mongodb\db\mongod.cfg

systemLog:
  destination: file
  path: "C:\\tools\\mongodb\\db\\log\\mongo.log"
  logAppend: true
storage:
  dbPath: "C:\\tools\\mongodb\\db\\data"
security:
  authorization: enabled

Upvotes: 16

Adam Mendoza
Adam Mendoza

Reputation: 5903

Here's an example of a mongodb.config file for Windows.

##store data here
dbpath=C:\mongodb\data\db

##all output go here
logpath=C:\mongodb\data\log\mongo.log

##log read and write operations
diaglog=3

Upvotes: 4

Related Questions