8

I installed mongodb on windows 8.1

then I use command promp to navigate to D:\mongodb\bin

then I use this command

mongod.exe --config D:\mongodb\mongodb.conf

The content of mongodb.conf

bind_ip = 127.0.0.1,100.100.100.100
port = 3979
quiet = true
dbpath = D:\mongodb\data\db
logpath = D:\mongodb\data\log\mongodb.log
logappend = true
journal = true

But mongod doesn't start. If I use mongod.exe (without using config file), it works perfectly

UPDATE:

My intention is simple: change default port to another port and only allow access from certain IP addresses.

I was using the configuration for Ubuntu. Thanks to Panda_Claus that pointed out the new configuration.

So I changed the configuration to

net:
   bindIp: 127.0.0.1,100.100.100.100
   port: 3979

The problem is, when I start mongod with this configuration, it got error then automatically exits

ERROR: listen(): bind() failed errno:10049 The requested address is not valid in its context. for socket: 100.100.100.100:3979

So how do I allow only localhost and a specific IP address (in this case is 100.100.100.100) to connect to mongodb?

UPDATE 2

I used the configuration from maerics

net:
  bindIp: 127.0.0.1,192.168.10.104
  port: 3979
storage:
  dbPath: D:\mongodb\data\db
  journal:
    enabled: true
systemLog:
  destination: file
  path: D:\mongodb\data\log\mongodb.log
  quiet: true
  logAppend: true

Interestingly, using this, I can only connect to db on local machine, other LAN computer can't connect to

192.168.10.104:3979. 

However, if I remove the

systemLog:
  destination: file
  path: D:\mongodb\data\log\mongodb.log
  quiet: true
  logAppend: true

other computers in LAN network are able connect to the database.

haipham23
  • 456
  • 2
  • 8
  • 21
  • Can you offer any more information besides "it doesn't start"? For example, is there any error message? – maerics Aug 08 '14 at 18:41
  • yes, when I use the first command, it doesn't show anything, like it doesn't run. If I use the second command, it shows alot of message like MongoDB starting : pid=... – haipham23 Aug 08 '14 at 18:46
  • Note that the `bind_ip` configuration value only determines which IP address(es) your MongoDB server is *listening* to. It does not control access from remote IPs -- that is the job of a [`firewall`](http://docs.mongodb.org/manual/tutorial/configure-linux-iptables-firewall/). – Stennie Aug 11 '14 at 03:12

4 Answers4

12

The config file must be valid YAML.

Try modifying the sample file provided with the documentation, for example:

net:
  bindIp: 127.0.0.1
  port: 3979
storage:
  dbPath: D:\mongodb\data\db
  journal:
    enabled: true
systemLog:
  destination: file
  path: D:\mongodb\data\log\mongodb.log
  quiet: true
  logAppend: true
maerics
  • 151,642
  • 46
  • 269
  • 291
  • thanks alot maerics! it only needs a small change: bind_ip => bindIp, dbpath => dbPath – haipham23 Aug 08 '14 at 19:23
  • @haipham23: right on! I've updated my answer to reflect those changes. – maerics Aug 08 '14 at 19:27
  • As at MongoDB 2.6, the config file can be either the new YAML format (introduced in 2.6) or the legacy INI-style [config file](http://docs.mongodb.org/v2.4/reference/configuration-options/) as first posted in the question. – Stennie Aug 11 '14 at 03:09
3

Not a mongo expert, but it appears from the mongo documentation that you should be using ":" as separators instead of "=".

Here's a link I found to support this:

[1]: [http://docs.mongodb.org/manual/reference/configuration-options/ "Mongo config file format"][1]

Panda_Claus
  • 103
  • 9
1

As others have already said, this error is pointing to an incorrect config file. Hence, it's always better to take the default conf file that comes bundled with mongo installation and make customizations atop that. On Linux based mongo installations, it can be found at /etc/mongod.conf. Below is the summary of the steps:

  1. Copy the default conf to a desired location. cp /etc/mongod.conf <desired_directory>/mymongod.conf
  2. Make the customizations and start mongod with the new config file. /usr/bin/mongod --config <desired_directory>/mymongod.conf
Binita Bharati
  • 5,239
  • 1
  • 43
  • 24
0

If Valid YAML doesn't solve your problem. Then you can try these steps.

Step 1: First check where your Mongod is installed. As in my case it is here: Check your path

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

enter image description here

Step 2: Check what is your config file name. like in my case, it is mongod.cfg. This is the default config. You can create your own or use the same, as I have created new for this sample: mongod_original.cfg. You can update the port or whatever you want here. like: (To edit the file, open the file in notepad as a administrator). Save the file, if it throws any error then check if your notepad is opened as administrator.

enter image description here

Step 3: Run cmd as administrator. and run this command for your config file:

mongod --config mongod_original.cfg

Output:

Your mongoDB will be started at the update port: 27000

enter image description here

Useful: If you get the error: exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: C:\Program Files\MongoDB\Server\4.0\data, terminating

Follow the link, based on your operating system, you can find the solution: MongoDB: exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating

KushalSeth
  • 3,265
  • 1
  • 26
  • 29