Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongod and mongo commands not working on windows 10

Tags:

mongodb

I've installed mongoDB on my windows 10 OS. Then I tried setting its database path to some directory by moving to it and typing mongod --datapath=data in cmd, where data is the folder which is to contain the db(I've used the relative path because I'm in that directory). But message comes that mongod is unrecognized command. After some searching I found that by specifying mongod path, i.e. "C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe" --datapath=data works. Similar thing happens for mongo.

I want to directly run mongod and mongo commands, I have seen people directly using it(without going to the directory or specifying the path).

like image 403
Shirish Bajpai Avatar asked Jul 07 '17 04:07

Shirish Bajpai


People also ask

Why is mongo command not working?

You can check that by running ls -alh /tmp/mongodb-27017. lock . To correct this issue, you can delete the file sudo rm /tmp/mongodb-27017. lock and then start the mongod process once more, which will recreate the file.

Does MongoDB support Windows 10?

Platform Support MongoDB 6.0 Community Edition supports the following 64-bit versions of Windows on x86_64 architecture: Windows Server 2019. Windows 10 / Windows Server 2016.


1 Answers

For a Windows installation, by default you have to use the full path to the exe unless you add it to the PATH.

To add it to the PATH:

01) Get path to bin, something like: C:\Program Files\MongoDB\Server\4.0\bin
02) Press the Windows key, type env, select Edit the system environment variables
03) On the Advanced tab, click Environment Variables
04) In the User variables for xxxx section, select path and then click the Edit... button
05) Click New and paste your path with a trailing slash, eg:
C:\Program Files\MongoDB\Server\4.0\bin\
06) Click OK, OK, OK and restart your command window.
Source

The examples you have seen are probably based on UNIX installations which I think by default install mongo as a service (which Windows doesn't) and that is what is called in those examples.

To simplify startup and configuration on Windows, you can also install it as a service. See the Mongo documentation here and the "Configure Windows Service for MongoDB' section".

This will then allow you to start and stop Mongo by simply calling

net start MongoDB

Or

net stop MongoDB
like image 197
welshGaz Avatar answered Sep 28 '22 01:09

welshGaz