The error message is below
MongoDB shell version: 3.2.11
connecting to: test
2020-05-16T20:53:47.438+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2020-05-16T20:53:47.440+0000 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:229:14
#(connect):1:6
By the way, is there any way to automatically seed the database in the Docker container? I have to manually seed the data base every time.
Thank you, guys.
did you map the port of your localhost to MongoDB container? if not add -p 27017:27017 to your docker run command.
If you are looking to seed the database upon initialization, you can use the following as stated on docker hub:
When a container is started for the first time it will execute files with extensions .sh and .js that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order. .js files will be executed by mongo using the database specified by the MONGO_INITDB_DATABASE variable, if it is present, or test otherwise. You may also switch databases within the .js script.
You can do this by mounting a javascript or shell script file via -v "./path/to/file.js:/docker-entrypoint-initdb.d/file.js" or via the volumes: ["./path/to/file.js:/docker-entrypoint-initdb.d/file.js"] key of your mongodb service if you are using docker-compose.
Related
i am a front stack dev trying to become full stack, been learning node and express and wanted to start with mongo, i went to the officlal mongodb page and followed the instruction to download mongo trough the cli in ubuntu 20.4
finished with the commands, i typed mongo in the command line and get this in mi cli
MongoDB shell version v4.4.4 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
what is that? im new at this side of coding and feel a bit overwelm by this, i appreciate the help you would give me
i had a similiar issue this probably happened because you failed to start mongodb service before opening the mongo shell.
next time run the command
sudo systemctl start mongod
this helps to start the mongodb service
to check if the service is running successfully you can then run the command
sudo systemctl status mongod
after which you can proceed to run the command
mongo
to run the mongo shell. this hack only applies to ubuntu system.
I wanted to move my PostgreSQL data folder on my Ubuntu server and I was following this tutorial to move it.
I was able to move it, and update my conf file to point to the new location.
When I go to run Postgres, it starts, but when I try to connect via
sudo -u postgres psql
It gives me this error:
psql: 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"?
Any ideas what happened? It says it's running.
After done moving PostgreSQL data directory. Don't forget to restart the PostgreSQL service.
Check the PostgreSQL status by command ps -ef | grep postgres. -D parameter value should be new directory location.
ERROR /var/run/postgresql/.s.PGSQL.5432 that's mean your PostgreSQL service not starting up Properly or Failed to when starting up.
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.
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.
My software process depends on the existence of a specific database in the local PostgreSQL cluster. PostgreSQL and my software process are both started by upstart on system start. A script is executed after PostgreSQL starts and before my software process starts to ensure the database is in the correct state.
The script dumps the schema of the database using pg_dump. If the server is not running or ready for connections I see the following
$ pg_dump -U postgres -s testdb
pg_dump: [archiver (db)] connection to database "testdb" failed: 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"?
If the database does not exist I see the following
$ pg_dump -U postgres -s testdb
pg_dump: [archiver (db)] connection to database "testdb" failed: FATAL: database "testdb" does not exist
There appears to be a time window where even though the cluster does contain database 'testdb' the call to pg_dump reports that the database does not exist. I can avoid the problem by adding a short sleep between server startup and running my script. I would prefer a solution that does not include a sleep for an arbitrary length of time. Any suggestions?
I'm running PostgreSQL 9.1 on 32bit Ubuntu 12.04 LTS.
Assuming this is a shell script, my guess is that you are not waiting for the create database command to complete. You could be running createdb n the background or psql in the background. If you run these in the foreground this should not happen because they will block until the database completes.