MongoDB on a Windows 7 machine: No connection could be made

前端 未结 14 1683
渐次进展
渐次进展 2020-12-02 10:39

After I have started Mongo using mongod.exe on a Windows 7 machine, I tried to start the mongo shell that failed with the error:

Failed to connect to

相关标签:
14条回答
  • 2020-12-02 11:20

    I had a very similar experience to @user1501382, but tweaked everything slightly in accordance with the documentation

    1) cd c: //changes to C drive

    2) mkdir data //creates directory data

    3) cd data

    4) mkdir db //creates directory db

    5) cd db //changes directory so that you are in c:/data/db

    6) run mongod -dbpath

    7) close this terminal, open a new one and run mongod

    0 讨论(0)
  • 2020-12-02 11:21

    for mongodb 3.0 versions use "--smallfiles".

    e.g:-

    mongod --dbpath="C:\Program Files\MongoDB\Server\3.0" --logpath="C:\Program Files\MongoDB\Server\3.0\data\log.txt" --smallfiles --install

    0 讨论(0)
  • 2020-12-02 11:24
    1. I assume your mongo.config file to be located inside the mongodb folder in the same level to the bin directory.The contents of the mongo.config file are:

      dbpath=C:\mongodb\data
      logpath=C:\mongodb\log\mongo.log
      diaglog=3
      

      don't forget to create the data folder and log folder in the same level of bin directory inside log folder create the mongo.log empty file.

    2. Point your command prompt to C:\mongodb\bin wherever your mongo db bin folder is located.

    3. create the mongo db service in windows typing

      mongod.exe --storageEngine=mmapv1 --config=../mongo.config 
      
    4. from now unwards you can start the mongo db service as

      net start mongodb
      
    5. finally you can connect to the mongo db server from the mongo db client typing

      mongo.exe
      
    6. once you have gone successfully from step 1 to step 3 from the next time on wards you only need the step 4 and 5.to start the service and to connect.

    0 讨论(0)
  • 2020-12-02 11:24

    I tried the above answer , and it worked, but had a very important problem: My previous collections were lost in another mongoDB data folder which I didn't know where they are and how to get them back.

    Before I run in to this mongo error, I was running mongo with no problem. When my windows10 boot files got corrupted and My computer went into blue screen, mongo ran into this error. So I just tried to retrieve the previous condition which I just was running mongo in one terminal and not mongod in another, so

    I repaired mongoDB with it's installation exe file, and now everything is ok.

    This is my mongoDB specs: mongodb-win32-x86_64-2012plus-4.2.1

    Hope this help you too.

    0 讨论(0)
  • 2020-12-02 11:26

    What solved my issue was creating a file startmongo.conf that sets the bind_ip to 127.0.0.1 . After that, I just created a *.bat to start the mongo using something like:

    mongod --config c:\mongodb\bin\startmongo.conf

    More details could be seem at this post .

    0 讨论(0)
  • 2020-12-02 11:26

    I was getting a similar error when I was trying to start my mongo db via cmd. However the difference was I had a config file which has the path to the db and log folders and wanted to use the same. I was using mongo few days back and it was running fine but when I started using it again today it was giving me the error :

    2015-05-27T10:33:22.820-0400 I CONTROL  Hotfix KB2731284 or later update is   installed, no need to zero-out data files
    MongoDB shell version: 3.0.2
    connecting to: test
    2015-05-27T10:33:23.854-0400 W NETWORK  Failed to connect to 27.0.0.1:27017, reason: errno:10061 No connection could be made because the target machine actively refused it.
    2015-05-27T10:33:23.857-0400 E QUERY    Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at connect src/mongo/shell/mongo.js:179:14) at (connect):1:6 at src/mongo/shell/mongo.js:179 exception: connect failed
    

    Here's how I fixed it :

    1. Open cmd as admin and navigate to the bin folder of your MongoDB and type : mongod --config <path to your config file> --install
    2. Now start your mongo db service : net start mongodb you should get a message which says : The MongoDB service was started successfully.
    3. close this command prompt and open another one as admin, navigate to the bin folder once again and type mongo

    This will connect you to the mongodb test.

    Press ctrl+c anytime to exit.

    Hope this helps.

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