How to connect to mongo server

Last modified by Leon Poon on 2021/03/23 13:17

If you have installed mongodb server, then in the console, type:

mongo

If you see the "couldn't connect" error, it means that your mongodb server is not running:

MongoDB shell version: 2.6.10                                                                                                                                                                                                                                                          
connecting to: test                                                                                                                                                                                                                                                                    
2017-07-12T20:55:00.407+0800 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused                                                                                                                                                                       
2017-07-12T20:55:00.407+0800 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146                                                                                                                                  
exception: connect failed

and you should start your server.

If you are able to connect, press CTRL-D to quit, and you can try using python to store and retrieve data from your mongodb server.