MongoError: could not connect to the server [localhost: 27017]

0

When I write on the command line return me this error:

MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
2018-05-01T11:42:17.843+0200 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-05-01T11:42:17.843+0200 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed

I need to access my database collections.

I do not think it's an installation error because it used to work.

Beforehand, thank you very much!

    
asked by Marifer Villarroel 01.05.2018 в 11:47
source

1 answer

0

This error usually occurs when we have not initialized the database server.

The mongo command is not the database, it is just a client in the shell. The steps would be.

1) open two terminals.

2) in one of them run mongod (with the necessary parameters, like the port ...), this runs the mongodb server. For example

mongod --port 27017

the console should be waiting for connections like this:

If it fails, the server will not be initialized and therefore the mongo command will never be executed successfully.

3) in the other terminal (once the server is loaded) you run mongo and in theory you should not throw yourself an error.

mongo

I hope it's your mistake.

here you can see the documentation to install and run mongodb on different platforms link

    
answered by 01.05.2018 в 18:49