Mongo shell not connecting
I have dedicated centos server
I installed mongodb as a service in my server from here
I even restarted server after installing mongodb
When i tries to run mongo shell it always saying
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 tried to remove that mongod.lock but no joy
I dont understand why this happens, because when mongod starts as a service it creates a log in system and telling that it has opened the door to listen incoming connection on port 27017. But it is throwing error while i connecting to mongo shell.
Please see this steps i have used --> click here
Well i wants to use this mongo service first of all at local based with only 127.0.0.1 access. I can change that in mongod.conf file afterward.
Be sure with iptables, Firwalll causing this kind of issue on live server.
So please do this if you facing this kind of same issue,
Do iptables off for a moment
# /etc/init.d/iptables stop
# sudo service mongod start
# mongo
Here what i wanted to see finally,
MongoDB shell version: 2.6.7
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
show dbs
admin (empty)
local 0.078GB
Thanks guys who considered my question and looking in it.
Thanks a lot.
Related
I installed mongodb in VS code by npm install mongodb. And again I downloaded mongodb from official website and installed it as a windows service since I don't know if installing in vscode with npm is enough. It worked for a while.
and now it doesn't work as my database connection with mongoose fails and nothing is running in 27017 port in localhost. Seems like server stopped.
how to restart mongodb server? what's the CLI/terminal command etc for that?
On debian/ubuntu
sudo service mongod restart
Go to services via start button and check for the MongoDB services shown in below pic. And rest steps you can follow which #apoorva has mentioned.
Open a mongo shell and execute,
use admin
db.shutdownServer()
You may start again with mongod.
Learn more here, https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/#StartingandStoppingMongo-SendingshutdownServer%28%29messagefromthemongoshell
If You Installed MongoDB as a Windows Service
The MongoDB service is started upon successful installation.(please check on the below path)
To begin using MongoDB, connect a mongo.exe shell to the running MongoDB instance. Either:
From Windows Explorer/File Explorer, go to
C:\Program Files\MongoDB\Server\4.4\bin\ directory and double-click on mongo.exe.
Or, open a Command Interpreter with Administrative privileges and run:
"C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe"
for more details check. : https://treehouse.github.io/installation-guides/windows/mongo-windows.html
Also, you first need to start the mongodb daemon for your connections to listen then you should connect using mongoose.
I am making an app on Node.js and trying to connect to MongoDB via mongoose. When I run it, in cmd it shows "connected to MongoDB database", but this is what it shows when I run mongo. It doesn't say connected
Mongo connection status
Also, when I try to connect MongoDB compass to localhost:27017, it shows the error " read ECONNRESET".
So clearly, for some reason, my MongoDB is not connected to the localhost. Can someone help me out? here is my mongoose connection code in app.js.
App.js Mongoose connection code
Can you check your mongod.conf file to see the port the server is set to run on.If on linux and running as a service use systemctl status mongod to ensure the process is running. Hope it helps.
Maybe you should run the command- " mongod " in another window and check.
If it's not connecting, simply go in that path:
C:\Program Files\MongoDB\Server\5.0\bin
and click shift + right, open window PowerShell or any other command prompt, and then type mongod like that:
PS C:\Program Files\MongoDB\Server\5.0\bin> mongod
and connect to it again.
Just followed these simple steps:
Type here to search -- Services -- Click on that
Find -- MongoDB Server(MongoDB) -- Click on that
On the left site of window You will see -- Start-- link. Click on that,
and your problem is solved.
I've been following this tutorial to install Rocket.Chat on Ubuntu:
https://github.com/RocketChat/Rocket.Chat/wiki/Deploy-Rocket.Chat-without-docker
Everything looks good until I try to run the server with node main.js:
Error: failed to connect to [localhost:27017]
at Object.Future.wait (/home/gregoire/Rocket.Chat/programs/server/node_modules/fibers/future.js:398:15)
at new MongoConnection (packages/mongo/mongo_driver.js:213:1)
localhost could also be 127.0.0.1 or my IP address, it doesn't change anything. Sounds like an error coming from MongoDB.
So I tried to run with sudo and the error I'm getting is different:
Error: MONGO_URL must be set in environment
I follow the tutorial, this variable has been set using export:
export ROOT_URL=http://localhost/
export MONGO_URL=mongodb://localhost:27017/rocketchat
export PORT=80
EDIT:
I needed to start mongod to then run the main.js. But I also got an error:
mongodb failed to connect to 127.0.0.1
I made some research and found that I had a missing folder. I used this command to create it and then started mongod:
mkdir -p /data/db
It worked after that, but it's not implied in the tutorial. I'm currently repeating the setup on a server and I'm having the same problem: /data/db is missing.
Disclaimer: I work for Rocket.Chat.
Are you sure mongodb is running? Can you type mongo and see if you can get into a mongoDB shell? If it's running, can you please confirm it's running on port 27017?
You can also go to https://demo.rocket.chat and join #support channel or #dev, where you'll find quite a few developers willing to help you out.
After simply installing MongoDB and creating \data\db within the MongoDB folder, I proceeded to run mongod.exe --dbpath C:\MongoDB\data\db. It runs a bunch of initandlisten code and then when it waits for connections on port 27017 it hangs and writes out mem res:47 virt:171 mapped:80 connections:0. I am very new to Mongo and haven't found a definitive answer on why this is hanging and how to fix it.
If you want to run the mongod.exe process as a service under Windows (to avoid it taking up a command prompt) you should following these directions for MongoDB 2.6.0 (2.6.0 has a bug with the normal approach to configuring MongoDB as a service).
There is a known issue for MongoDB 2.6.0, SERVER-13515, which prevents
the use of the instructions in this section. For MongoDB 2.6.0, use
Manually Create a Windows Service for MongoDB to create a Windows
Service for MongoDB instead.
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/#manually-create-windows-service
For MongoDB versions 2.6.1 and later follow the normal directions:
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/#configure-a-windows-service-for-mongodb
Mongo waiting on 27017 even after reinstall
The waiting for connections message in the console output indicates that the mongod.exe process is running successfully.
After you install MongoDB, you need to connect to MongoDB through mongo.exe shell using another command prompt.
As soon as you are done with that, the waiting message in first console would change to connection accepted.
I downloaded postgresql-9.1.
but when I execute the command in terminal:
$ createdb mydb
I get the following message:
createdb: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
please tell me how to sort this problem.I have even tried to uninstall and then reinstall it. I am trying to run this on linux mint 15 (cinnamon).
Use ps to see if the postgresql process is actually running. If not, start it (service postgresql start). Normally should start up itself on boot after installation but who knows. Also, some error may prevent it from starting on boot.
If postgresql is running, then you may need to edit pg_hba.conf in the data directory. Again, normally the database should listen for local connections by default but who knows.