mongod command not recognized when trying to connect to a mongodb server

后端 未结 14 625
暖寄归人
暖寄归人 2021-01-31 01:11

I am following the tutorials at docs.mongodb.org, I have completed the first tutorial which was to install mongodb on a windows machine. I am now at the second stage which is ge

相关标签:
14条回答
  • 2021-01-31 01:40

    You need to add Mongo's bin folder to the "Path" Environment Variable

    Here's how on Windows 10:

    1. Find Mongo's bin folder.

    If you're not sure where it is, it's probably in C:\Program Files\MongoDB\Server\3.4\ 3.4 was the latest stable version at the time, this will be different for you probably.

    It should look like this:

    Notice this is the path to mongo.exe and mongod.exe. Adding this folder to the Path variable is telling Windows to search in this folder for executables matching your command when you run something in cmd. The search starts with the current working dir, and if it doesn't find your exe, goes on to search all the paths in Path till it finds it or it doesn't and it gives you that error you saw.

    1. Copy the path to the bin folder. It should be C:\Program Files\MongoDB\Server\3.4\bin\ (Or whatever version you're using)

    2. Press win, type env, Windows will suggest "Edit the System Environment Variables", click that.

    1. On the Advanced tab, click "Environment Variables"

    1. Highlight the "Path" variable, click "Edit":

    1. This will bring up the "Edit environment variable" window, click "New"

    1. This will start a new line in the list of folders:

    1. Paste your path to the bin folder. Make sure it ends with a \ like so:

    1. Press "OK", "OK", "OK"

    Now you should be able to run mongod and mongo from anywhere in a command window.

    0 讨论(0)
  • 2021-01-31 01:40

    Are you sure that you have specified the correct paths?

    You need to be in the right directory, i.e.

    C:\Program Files\MongoDB\bin
    

    and the path you are installing into needs to be the correct one

    i.e.

    mongod --dbpath 
    C:\Users\Name\Documents\myWebsites\nodetest1
    

    A folder named "data" must also exist in your project folder.

    I got the same error and this worked for me.

    0 讨论(0)
  • 2021-01-31 01:47

    You need to run mongod first in one cmd window then open another and type mongo. Make sure you updated your Windows Path environment variable too so that you don't have to navigate to the directory you have all of the mongo binaries in to start the application. To update the Path variable:

    Go to Control Panel > System & Security > System > Advanced System Settings > Environment Variables > navigate to the Path variable hit Edit and add ;C:\mongodb to the Path (or whatever the directory name is where MongoDB is located (the semi-colon delimits each directory).

    0 讨论(0)
  • 2021-01-31 01:48

    Adding MongoDb bin path in Environment path with \ worked for me

    This is what my system path

    C:\ProgramData\Oracle\Java\javapath;
    ...
    ...
    Other path variables
    ...
    ;C:\Users\hitesh.sahu\AppData\Local\Android\sdk\platform-tools
    ;C:\Program Files\MongoDB\Server\3.2\bin\
    

    Make sure:-

    • Environment path must not have space between them
    • Environment path must be saparated by ;
    0 讨论(0)
  • 2021-01-31 01:52

    putting backslash "/" at the end of path to bin of mongodb solved my problem.

    0 讨论(0)
  • 2021-01-31 01:53

    if still not working for you then just close all of your command prompts and then again open and run mongo, mongoimport, mongodb from anywhere it ll work because after setting the path variable command prompt should be restarted.

    0 讨论(0)
提交回复
热议问题