1

I created a command (start.cmd) file with the following contents:

c:\pymon\mongodb\bin\mongod.exe --dbpath c:\pymon\mongodb\data

But all it does is open a new blank command shell.

I then tried:

cmd /c c:\pymon\mongodb\bin\mongod.exe --dbpath c:\pymon\mongodb\data

But that does the same thing.

All I want is to start mongo using my own database path without having to specify the dbpath. I thought it could be done with a configuration file, but reading the documentation you've got to supply a parameter to mongod.exe to use the config file meaning my above cmd file still wouldn't work.

What am I doing wrong? any other program starts fine using the above.

Thanks.

Neil Walker
  • 6,400
  • 14
  • 57
  • 86

6 Answers6

7

Please follow these simple steps to create a bat file, Which will run your mongo-server just on the click of this bat file. Instead of we manually configuring the path each time while starting the server.

  • Step 1: Create a empty bat file on your desktop, Name it as startmongoserver.bat enter image description here
  • Step 2: Right click on this bat file, Edit (with notepad) and then paste this code start call "C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe" --dbpath /Users/tsabu/Mongodb-data
    enter image description here Note : In above example /Users/tsabu/Mongodb-data is the path to your folder which store all your mongodb data. To generalize this path /Users/(admin or user-name)/(folder-name) enter image description here
  • Step 3: Save this startmongoserver.bat file , close the notepad (editor) and then run this (.bat) file.
Sabunkar Tejas Sahailesh
  • 4,436
  • 2
  • 28
  • 32
2

create a batch file ...bat with

start call "C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe"
start call "C:\Program Files\MongoDB\Server\3.4\bin\mongo.exe"
Gabriel
  • 595
  • 7
  • 10
1

A straightforward way is to create config file mongod.cfg that contains like below:

systemLog:
  destination: file
  path: C:\Program Files\MongoDB\Server\3.6\bin\data\log\mongod.log
storage:
  dbPath: C:\Program Files\MongoDB\Server\3.6\bin\data\db
net:
  bindIp: 127.0.0.1
  port: 27017

then run this command in the bin folder inside mongodb:

mongod --config mongod.cfg

If you want to install as MongoDB service you should run like this, be sure to write absolute path for mongod.cfg:

mongod --config "C:\ProgramFiles\MognoDB\Server\...\bin\mongod.cfg" --install

If you don't mention absolute path in the command or inside config file when you want to install as windows service, it will give error. Then you can start MongoDB service with:

net start MongoDB
Jalaleddin Hosseini
  • 2,142
  • 2
  • 25
  • 28
0

In both the approaches, you are spinning off a shell that starts the mongod process and exits. Have you considered using Mongodb as a windows service?

The --install option of mongod.exe can help you set it up. Refer here

Edit: Actually, what I said above isn't true. I could get a cmd file to work.

start.cmd

"c:\Program Files\MongoDB 2.6 Standard\bin\mongod.exe" --dbpath c:\mongodbdata\temp
Srikanth Venugopalan
  • 9,011
  • 3
  • 36
  • 76
0

If you run my command from File explorer it works fine, but from a command line it has the problem I created.

So, from a command line you can do:

cmd /c start.cmd

and it works.

Neil Walker
  • 6,400
  • 14
  • 57
  • 86
0

Create a file with bat extension, right click and edit the file, paste mongo installation path. For me as windows user

start call "C:\Program Files\MongoDB\Server\5.0\bin\mongod.exe"

Double click on bat file with run the mongo

muhammad shahan
  • 517
  • 6
  • 17