error mongo without mongod running first locally in win 10 - mongodb

I have this mongo.zip installed in my win 10.
I have set the environment path with bin.
Somehow whenever I start command line,
my mongo cannot start without mongod first.
C:\Users\asus>mongo
MongoDB shell version v4.4.1
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: No connection could be made because the target machine actively refused it. :
connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6
exception: connect failed
exiting with code 1
but if I run mongod before mongo, mongo is running perfectly.
So, my question is: how do I running mongo without mongod locally.
PS. my compass is running and can connect to AWS cloud.
Please provide pictures if you can.
Thank you!

I think you, first of all, you have to know about the difference between them.
Mongod is the process of MongoDB.
Mongo is a shell. You can use it to connect and run any mongo command on any MongoDB.
So, your error means;
You are trying to connect your own MongoDB with typed mongo, because the default -host parameter is localhost. But your mongod process is not running. So you have to start it.
connecting to: mongodb://127.0.0.1:27017
127.0.0.1:27017 equals localhost.
If you have MongoDB (mongod process) on AWS. You should connect with below command
mongo --host mongodb0.example.com:28015

Related

Having trouble installing/uninstalling MONGODB

I am trying to install MONGODB, followed a bunch of tutorials and haven't had luck. Prior to this, when I typed mongo in the terminal, it would say it wasn't found. However I stumbled upon https://www.mongodb.com/community/forums/t/unable-to-connect-to-mongo-shell-error-connecting-to-127-0-0-1-27017-caused-by-connection-refused-connect-src-mongo-shell-mongo-js13/89945/2 and copied
>mongo "mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/100YWeatherSmall?replicaSet=Cluster0-shard-0" --authenticationDatabase admin --ssl --username m001-student --password m001-mongodb-basics
into my terminal. I want to restart fresh and get rid of everything related to mongo. However, even after following the instructions from https://www.mongodb.com/basics/uninstall-mongodb for mac, I can't seem to restart fresh. I seem to get
MongoDB shell version v5.0.9
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:372:17
#(connect):2:6
exception: connect failed
exiting with code 1
My problem is that I am having trouble installing MongoDB and ended up blindly copying something. Now I can't seem to go back to the original message where after I type mongo, it would give the message saying it wasn't found. Instead, I get the message that I mentioned above. Any ideas on how to fix this? Thanks!
You may want to try these commands to repair and restart your mongodb server:
1) Remove .lock file
sudo rm /var/lib/mongodb/mongod.lock
2) repair the mongodb
mongod -–repair
3) start the mongod server
sudo service mongod start
4) start the mongo client
mongo

Running `mongo` in the command line is giving error

I am trying to start a MERN app, I have installed mongo and any relevant things. But when I run mongo in my terminal the following appears.
I have looked across the board but the solutions do not help me. I am also running on Ubuntu 20.04.
MongoDB shell version v4.4.3
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6
exception: connect failed
exiting with code 1
Fixed the issue by running
$ sudo rm -rf /tmp/mongodb-27017.sock
$ sudo service mongod start
Try to start the MongoDB server first running mongod command or from task manager>services> MongoDB server> right-click and start it
Read this Document for more

Could not run MongoDB server in Ubuntu system

I am trying to run MongoDB in my Ubuntu machine using the following command but I am getting some error.
Command:
mongo
Error:
connecting to: mongodb://127.0.0.1:27017<br>
2019-12-23T17:00:38.815+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused<br>
2019-12-23T17:00:38.818+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :<br>
connect#src/mongo/shell/mongo.js:251:13<br>
#(connect):1:6<br>
exception: connect failed
How can I resolve this issue and run MongoDB successfully?
Normally this is caused because you didn't start mongodb service before you try starting mongo shell. You can check for a system service status. If it is failing because of some error try to fix it and start the process. Below are few things that might help with it.
Check if mongodb service is up and running
sudo systemctl status mongodb
If not start mongodb service on your ubuntu machine
sudo systemctl start mongodb
Start mongo shell
mongo

Already running Mongo db start up issue in ubuntu

I have issue with Mongo DB start up in ubuntu 14.04 64 bit,its working fine when i installed first time but suddenly from now when i type mongo in ubuntu terminal its showing error:
MongoDB shell version: 3.0.7
connecting to: test
2015-11-26T11:59:03.888+0530 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-11-26T11:59:03.889+0530 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
I tried many solution
i.e
1.deleting lock files, and restart mongo,
2.Change bind ip to 0.0.0.0 in mongod.conf
but my issue still not resolved.
Try to execute the following command to grep process id of mongod to determine if mongo service is running or not
pgrep mongod
If process id exists then please follow the steps as mentioned below
(a) Kill existing mongod process using following command
sudo kill -9 [process_id]
(b) Start mongod process using
sudo mongod --noauth --dbpath /var/lib/mongodb

can't run mongo as a service

So I've got a virtual machine running on windows azure and installed mongoDB. However mongod works fine when I do: mongod --dbpath /mnt/datadrive/data but when I end the process and do mongo, I get:
2015-01-10T14:23:17.474+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-01-10T14:23:17.476+0000 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
I've edited the config /etc/mongod.config however when I try and run sudo service mongo start I get:
Job for mongod.service failed. See 'systemctl status mongod.service' and 'journalctl -xn' for details.
What I'm initially trying to do is have mongoDB running as a service on my virtual machine so I can remotely can connect to it at anytime.
When you typed in the mongod command, did you also give it a path? This is usually the issue. You don't have to bother with the conf file. simply type
mongod --dbpath="put your path to where you want it to save the working area for your database here!! without these silly quotations marks I may also add!"
example: mongod --dbpath=C:/Users/Kyle-3/Desktop/DEV/dangerzonearea/test/mongodb
That is my path and don't forget if on windows to flip the slashes forward if you copied it from the or it won't work!
Solution:
Don't end the service. Let it continue while you use mongo from another cmd or shell.