When starting my app, I get the following error:
error: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkTimeoutError: connection timed out
backend_1 | at connectionFailureError (/usr/src/app/node_modules/mongodb/lib/core/connection/connect.js:342:14)
backend_1 | at Socket.<anonymous> (/usr/src/app/node_modules/mongodb/lib/core/connection/connect.js:310:16)
backend_1 | at Object.onceWrapper (events.js:421:28)
backend_1 | at Socket.emit (events.js:315:20)
backend_1 | at Socket._onTimeout (net.js:483:8)
backend_1 | at listOnTimeout (internal/timers.js:554:17)
backend_1 | at processTimers (internal/timers.js:497:7)]
backend_1 | at Pool.<anonymous> (/usr/src/app/node_modules/mongodb/lib/core/topologies/server.js:438:11)
backend_1 | at Pool.emit (events.js:315:20)
backend_1 | at /usr/src/app/node_modules/mongodb/lib/core/connection/pool.js:562:14
backend_1 | at /usr/src/app/node_modules/mongodb/lib/core/connection/pool.js:995:11
backend_1 | at /usr/src/app/node_modules/mongodb/lib/core/connection/connect.js:32:7
backend_1 | at callback (/usr/src/app/node_modules/mongodb/lib/core/connection/connect.js:280:5)
backend_1 | at Socket.<anonymous> (/usr/src/app/node_modules/mongodb/lib/core/connection/connect.js:310:7)
backend_1 | at Object.onceWrapper (events.js:421:28)
backend_1 | at Socket.emit (events.js:315:20)
backend_1 | at Socket._onTimeout (net.js:483:8)
backend_1 | at listOnTimeout (internal/timers.js:554:17)
backend_1 | at processTimers (internal/timers.js:497:7),
However, I can connect to the MongoDB service via MongoDBCompass and the Database connection tool in WebStorm, using the same connection string. "mongodb://localhost:27017/fmis"
I'm struggling to find the root cause to even try and solve it myself.
Update: as asked in the comments, I am running docker
I solved this by including the following in my connection configuration:
mongoose.connect(
db,
{
...
useUnifiedTopology: true //THIS SETTING
})
...
)
Related
Server is running on port 5000 successfully, but unable to connect to the mongoDB atlas database
mymanager-server | /usr/src/app/node_modules/mongodb/lib/cmap/connect.js:375
mymanager-server | return new error_1.MongoNetworkError(err);
mymanager-server | ^
mymanager-server |
mymanager-server | MongoNetworkError: getaddrinfo EAI_AGAIN mymanager-shard-00-01.qrauq.mongodb.net
mymanager-server | at connectionFailureError (/usr/src/app/node_modules/mongodb/lib/cmap/connect.js:375:20)
mymanager-server | at TLSSocket.<anonymous> (/usr/src/app/node_modules/mongodb/lib/cmap/connect.js:295:22)
mymanager-server | at Object.onceWrapper (node:events:628:26)
mymanager-server | at TLSSocket.emit (node:events:513:28)
mymanager-server | at TLSSocket.emit (node:domain:489:12)
mymanager-server | at emitErrorNT (node:internal/streams/destroy:157:8)
mymanager-server | at emitErrorCloseNT (node:internal/streams/destroy:122:3)
mymanager-server | at processTicksAndRejections (node:internal/process/task_queues:83:21) {
mymanager-server | [Symbol(errorLabels)]: Set(0) {}
mymanager-server | }
docker-compose.yml
version: "3"
services:
mymanager_b:
build: ./mymanager_b
container_name: mymanager-server
command: yarn prod
restart: unless-stopped
ports:
- "5000:5000"
networks:
- mm-network
networks:
mm-network:
driver: bridge
docker-compose-dev.yml
version: "3"
services:
mymanager_b:
command: yarn dev
volumes:
- ./mymanager_b:/usr/src/app
- /usr/src/app/node_modules
And I have a separate .env file for the MONGO_URI
I expect it to run mongoDB as a normal dev environment
Hello I'm trying to launch the FIWARE orion context broker using an atlas mongodb
mongodb+srv://<user>:****************#<domainid>.mongodb.net/<aut_db>
I have tried multiple variations of the docker run command but I never get the connection to success
trace:
$ docker run --name orion -p 1027:1026 fiware/orion:latest -dbhost "<domainid>.mongodb.net/<aut_db>?ssl=true&retryWrites=true&w=majority" -dbuser <user> -dbpwd U9NjLafksdv9mavW -logLevel DEBUG
time=2021-12-01T14:38:42.188Z | lvl=INFO | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=contextBroker.cpp[1063]:main | msg=start command line </usr/bin/contextBroker -fg -multiservice -ngsiv1Autocast -disableFileLog -dbhost <domainid>.mongodb.net/<aut_db>?ssl=true&retryWrites=true&w=majority -dbuser <user> -dbpwd ****** -logLevel DEBUG>
time=2021-12-01T14:38:42.188Z | lvl=INFO | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=contextBroker.cpp[1137]:main | msg=Orion Context Broker is running
time=2021-12-01T14:40:23.011Z | lvl=ERROR | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=mongoConnectionPool.cpp[220]:mongoConnect | msg=Database Startup Error (cannot connect to mongo - doing 100 retries with a 1000 millisecond interval)
time=2021-12-01T14:40:23.011Z | lvl=FATAL | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=MongoGlobal.cpp[142]:mongoInit | msg=Fatal Error (MongoDB error)
time=2021-12-01T14:40:23.012Z | lvl=INFO | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=contextBroker.cpp[591]:exitFunc | msg=Orion shutdown completed
Has someone know how I can configure orion context broker to connect to an mongo atlas?
EDIT: I have checked and I have access from that server to the mongo-db with the mongo shell
Orion currently supports only mongodb:// connection strings, built from the -db, -dbhost, -rplSet, -dbTimeout, -dbuser, -dbpwd, -dbAuthMech, -dbAuthDb, -dbSSL and -dbDisableRetryWrites CLI parameters(or default values, if omitted) as can be see in the source code.
There is an issue in the Orion repository with the aim of making this more flexible, allowing to provide the connection string directly overriding the above parameters.
While that issue comes (contributions welcome ;) you could hack the Orion source code cited above to build an specific version for you with support for mongo+srv:// connection strings.
I set up a Minikube-Cluster with the MongoDB Community Kubernetes Operator.
To view the content i want to set up a mongo-express Instance which connects to the Mongo-Cluster/ReplicaSet. But if I apply the Deployment the Container always fails with:
mongo-express_1 | Waiting for localhost:27017...
mongo-express_1 | Welcome to mongo-express
mongo-express_1 | ------------------------
mongo-express_1 |
mongo-express_1 |
mongo-express_1 | Mongo Express server listening at http://0.0.0.0:8081
mongo-express_1 | Server is open to allow connections from anyone (0.0.0.0)
mongo-express_1 | basicAuth credentials are "admin:pass", it is recommended you change this in your config.js!
mongo-express_1 | Database connected
mongo-express_1 | Admin Database connected
mongo-express_1 | Error [MongoError]: Authentication failed.
mongo-express_1 | at Function.MongoError.create (/node_modules/mongodb-core/lib/error.js:31:11)
mongo-express_1 | at /node_modules/mongodb-core/lib/connection/pool.js:483:72
mongo-express_1 | at authenticateStragglers (/node_modules/mongodb-core/lib/connection/pool.js:429:16)
mongo-express_1 | at Connection.messageHandler (/node_modules/mongodb-core/lib/connection/pool.js:463:5)
mongo-express_1 | at Socket.<anonymous> (/node_modules/mongodb-core/lib/connection/connection.js:319:22)
mongo-express_1 | at Socket.emit (events.js:314:20)
mongo-express_1 | at addChunk (_stream_readable.js:297:12)
mongo-express_1 | at readableAddChunk (_stream_readable.js:272:9)
mongo-express_1 | at Socket.Readable.push (_stream_readable.js:213:10)
mongo-express_1 | at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
mongo-express_1 | operationTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1611234788 },
mongo-express_1 | ok: 0,
mongo-express_1 | errmsg: 'Authentication failed.',
mongo-express_1 | code: 18,
mongo-express_1 | codeName: 'AuthenticationFailed',
mongo-express_1 | '$clusterTime': {
mongo-express_1 | clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1611234788 },
mongo-express_1 | signature: { hash: [Binary], keyId: [Long] }
mongo-express_1 | }
mongo-express_1 | }
mongo-express_1 | unable to list databases
mongo-express_1 | Error [MongoError]: command listDatabases requires authentication
mongo-express_1 | at Function.MongoError.create (/node_modules/mongodb-core/lib/error.js:31:11)
mongo-express_1 | at /node_modules/mongodb-core/lib/connection/pool.js:483:72
mongo-express_1 | at authenticateStragglers (/node_modules/mongodb-core/lib/connection/pool.js:429:16)
mongo-express_1 | at Connection.messageHandler (/node_modules/mongodb-core/lib/connection/pool.js:463:5)
mongo-express_1 | at Socket.<anonymous> (/node_modules/mongodb-core/lib/connection/connection.js:319:22)
mongo-express_1 | at Socket.emit (events.js:314:20)
mongo-express_1 | at addChunk (_stream_readable.js:297:12)
mongo-express_1 | at readableAddChunk (_stream_readable.js:272:9)
mongo-express_1 | at Socket.Readable.push (_stream_readable.js:213:10)
mongo-express_1 | at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
mongo-express_1 | operationTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1611234788 },
mongo-express_1 | ok: 0,
mongo-express_1 | errmsg: 'command listDatabases requires authentication',
mongo-express_1 | code: 13,
mongo-express_1 | codeName: 'Unauthorized',
mongo-express_1 | '$clusterTime': {
mongo-express_1 | clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1611234788 },
mongo-express_1 | signature: { hash: [Binary], keyId: [Long] }
mongo-express_1 | }
mongo-express_1 | }
For the ease of testing I used docker-compose to start mango-express and created a Port-Forwarding to access the cluster.
Versions:
MongoDB Cluster: tried 4.2.6 and 4.4.3
mongo-express: 0.54.0
Here the Deployment/Service I use for MongoDB Cluster creation:
---
apiVersion: mongodb.com/v1
kind: MongoDB
metadata:
name: example-mongodb
spec:
members: 3
type: ReplicaSet
version: "4.4.3"
security:
authentication:
modes: ["SCRAM"]
users:
- name: mongoadmin
db: admin
passwordSecretRef: # a reference to the secret that will be used to generate the user's password
name: mongoadmin-password
roles:
- name: root
db: admin
scramCredentialsSecretName: my-scram
# the user credentials will be generated from this secret
# once the credentials are generated, this secret is no longer required
---
apiVersion: v1
kind: Secret
metadata:
name: mongoadmin-password
type: Opaque
stringData:
password: mongoadmin
And here the compose-file i use for mongo-express:
version: '3.8'
services:
mongo-express:
image: mongo-express
restart: on-failure
ports:
- 8081:8081
network_mode: host
environment:
ME_CONFIG_MONGODB_SERVER: localhost
ME_CONFIG_MONGODB_ADMINUSERNAME: mongoadmin
ME_CONFIG_MONGODB_ADMINPASSWORD: mongoadmin
The thing is, that if I setup up a mongo (4.4.3) container with mongo-express via docker-compose everything works fine...
Does anybody have a clue whats going on?
I have build the docker image from the alpha version of mongo-express
https://github.com/mongo-express/mongo-express/tree/v1.0.0-alpha.1
Here is the image uncl3mar1k/mongo-express:v1.0.0-alpha.1
It seems to work well with authentication, but I noticed that it has an issue with pagening. (if you have a lot of collections and try to go through pages, you will notice that data about collections did not changes)
Update: there is a newer version v1.0.0-alpha.3 looks like all issues was fixed here. Please take a look to new image: staslb/mongo-express:v1.0.0-alpha.3
I used SpringBoot rest api and MongoDB. I have three different DataBases such as player-db, game-db and score-db. for each services I have DockerFiles.
when I run docker-compose up I've Getting an Error:
The error in docker-shell:
game-docker_1 | 2020-06-12 09:12:03.795 INFO 1 --- [localhost:27017] org.mon
godb.driver.cluster : Exception in monitor thread while connecting
to server localhost:27017
game-docker_1 |
game-docker_1 | com.mongodb.MongoSocketOpenException: Exception opening socke
t
game-docker_1 | at com.mongodb.internal.connection.SocketStream.open(Soc
ketStream.java:70) ~[mongo-java-driver-3.11.2.jar!/:na]
game-docker_1 | at com.mongodb.internal.connection.InternalStreamConnect
ion.open(InternalStreamConnection.java:128) ~[mongo-java-driver-3.11.2.jar!/:na]
game-docker_1 | at com.mongodb.internal.connection.DefaultServerMonitor$
ServerMonitorRunnable.run(DefaultServerMonitor.java:117) ~[mongo-java-driver-3.1
1.2.jar!/:na]
game-docker_1 | at java.lang.Thread.run(Thread.java:748) [na:1.8.0_252]
game-docker_1 | Caused by: java.net.ConnectException: Connection refused (Con
nection refused)
game-docker_1 | at java.net.PlainSocketImpl.socketConnect(Native Method)
~[na:1.8.0_252]
game-docker_1 | at java.net.AbstractPlainSocketImpl.doConnect(AbstractPl
ainSocketImpl.java:350) ~[na:1.8.0_252]
game-docker_1 | at java.net.AbstractPlainSocketImpl.connectToAddress(Abs
tractPlainSocketImpl.java:206) ~[na:1.8.0_252]
game-docker_1 | at java.net.AbstractPlainSocketImpl.connect(AbstractPlai
nSocketImpl.java:188) ~[na:1.8.0_252]
game-docker_1 | at java.net.SocksSocketImpl.connect(SocksSocketImpl.java
:392) ~[na:1.8.0_252]
game-docker_1 | at java.net.Socket.connect(Socket.java:607) ~[na:1.8.0_2
52]
game-docker_1 | at com.mongodb.internal.connection.SocketStreamHelper.in
itialize(SocketStreamHelper.java:64) ~[mongo-java-driver-3.11.2.jar!/:na]
game-docker_1 | at com.mongodb.internal.connection.SocketStream.initiali
zeSocket(SocketStream.java:79) ~[mongo-java-driver-3.11.2.jar!/:na]
game-docker_1 | at com.mongodb.internal.connection.SocketStream.open(Soc
ketStream.java:65) ~[mongo-java-driver-3.11.2.jar!/:na]
game-docker_1 | ... 3 common frames omitted
game-docker_1 |
player-docker_1 | 2020-06-12 09:12:03.810 INFO 1 --- [localhost:27017] org.mon
godb.driver.cluster : Exception in monitor thread while connecting
to server localhost:27017
player-docker_1 |
player-docker_1 | com.mongodb.MongoSocketOpenException: Exception opening socke
t
player-docker_1 | at com.mongodb.internal.connection.SocketStream.open(Soc
ketStream.java:70) ~[mongo-java-driver-3.11.2.jar!/:na]
player-docker_1 | at com.mongodb.internal.connection.InternalStreamConnect
ion.open(InternalStreamConnection.java:128) ~[mongo-java-driver-3.11.2.jar!/:na]
player-docker_1 | at com.mongodb.internal.connection.DefaultServerMonitor$
ServerMonitorRunnable.run(DefaultServerMonitor.java:117) ~[mongo-java-driver-3.1
1.2.jar!/:na]
player-docker_1 | at java.lang.Thread.run(Thread.java:748) [na:1.8.0_252]
player-docker_1 | Caused by: java.net.ConnectException: Connection refused (Con
nection refused)
player-docker_1 | at java.net.PlainSocketImpl.socketConnect(Native Method)
~[na:1.8.0_252]
player-docker_1 | at java.net.AbstractPlainSocketImpl.doConnect(AbstractPl
ainSocketImpl.java:350) ~[na:1.8.0_252]
player-docker_1 | at java.net.AbstractPlainSocketImpl.connectToAddress(Abs
tractPlainSocketImpl.java:206) ~[na:1.8.0_252]
player-docker_1 | at java.net.AbstractPlainSocketImpl.connect(AbstractPlai
nSocketImpl.java:188) ~[na:1.8.0_252]
player-docker_1 | at java.net.SocksSocketImpl.connect(SocksSocketImpl.java
:392) ~[na:1.8.0_252]
player-docker_1 | at java.net.Socket.connect(Socket.java:607) ~[na:1.8.0_2
52]
player-docker_1 | at com.mongodb.internal.connection.SocketStreamHelper.in
itialize(SocketStreamHelper.java:64) ~[mongo-java-driver-3.11.2.jar!/:na]
player-docker_1 | at com.mongodb.internal.connection.SocketStream.initiali
zeSocket(SocketStream.java:79) ~[mongo-java-driver-3.11.2.jar!/:na]
player-docker_1 | at com.mongodb.internal.connection.SocketStream.open(Soc
ketStream.java:65) ~[mongo-java-driver-3.11.2.jar!/:na]
player-docker_1 | ... 3 common frames omitted
player-docker_1 |
score-docker_1 | 2020-06-12 09:12:03.893 INFO 1 --- [localhost:27017] org.mon
godb.driver.cluster : Exception in monitor thread while connecting
to server localhost:27017
score-docker_1 |
score-docker_1 | com.mongodb.MongoSocketOpenException: Exception opening socke
t
score-docker_1 | at com.mongodb.internal.connection.SocketStream.open(Soc
ketStream.java:70) ~[mongo-java-driver-3.11.2.jar!/:na]
score-docker_1 | at com.mongodb.internal.connection.InternalStreamConnect
ion.open(InternalStreamConnection.java:128) ~[mongo-java-driver-3.11.2.jar!/:na]
score-docker_1 | at com.mongodb.internal.connection.DefaultServerMonitor$
ServerMonitorRunnable.run(DefaultServerMonitor.java:117) ~[mongo-java-driver-3.1
1.2.jar!/:na]
score-docker_1 | at java.lang.Thread.run(Thread.java:748) [na:1.8.0_252]
score-docker_1 | Caused by: java.net.ConnectException: Connection refused (Con
nection refused)
score-docker_1 | at java.net.PlainSocketImpl.socketConnect(Native Method)
~[na:1.8.0_252]
score-docker_1 | at java.net.AbstractPlainSocketImpl.doConnect(AbstractPl
ainSocketImpl.java:350) ~[na:1.8.0_252]
score-docker_1 | at java.net.AbstractPlainSocketImpl.connectToAddress(Abs
tractPlainSocketImpl.java:206) ~[na:1.8.0_252]
score-docker_1 | at java.net.AbstractPlainSocketImpl.connect(AbstractPlai
nSocketImpl.java:188) ~[na:1.8.0_252]
score-docker_1 | at java.net.SocksSocketImpl.connect(SocksSocketImpl.java
:392) ~[na:1.8.0_252]
score-docker_1 | at java.net.Socket.connect(Socket.java:607) ~[na:1.8.0_2
52]
score-docker_1 | at com.mongodb.internal.connection.SocketStreamHelper.in
itialize(SocketStreamHelper.java:64) ~[mongo-java-driver-3.11.2.jar!/:na]
score-docker_1 | at com.mongodb.internal.connection.SocketStream.initiali
zeSocket(SocketStream.java:79) ~[mongo-java-driver-3.11.2.jar!/:na]
score-docker_1 | at com.mongodb.internal.connection.SocketStream.open(Soc
ketStream.java:65) ~[mongo-java-driver-3.11.2.jar!/:na]
score-docker_1 | ... 3 common frames omitted
score-docker_1 |
game-docker_1 | 2020-06-12 09:12:06.823 INFO 1 --- [ main] o.s.s.c
oncurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTas
kExecutor'
player-docker_1 | 2020-06-12 09:12:06.895 INFO 1 --- [ main] o.s.s.c
oncurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTas
kExecutor'
The docker-compose.yml:
version: "3"
services:
player-docker:
build:
context: ./
dockerfile: ./src/main/java/spring/multiple/mongo/project/player/DockerFile
restart: always
ports:
- 8080:8080
depends_on:
- db
game-docker:
build:
context: ./
dockerfile: ./src/main/java/spring/multiple/mongo/project/game/DockerFile
restart: always
ports:
- 8081:8080
depends_on:
- db1
score-docker:
build:
context: ./
dockerfile: ./src/main/java/spring/multiple/mongo/project/score/Dockerfile
restart: always
ports:
- 8082:8080
depends_on:
- db2
db:
image: mongo
volumes:
- mongodata:/data/db
ports:
- 27017:27017
restart: always
environment:
MONGO_INITDB_ROOT_DATABASE: player-db
db1:
image: mongo
volumes:
- mongodata:/data/db1
ports:
- 27018:27017
restart: always
environment:
MONGO_INITDB_ROOT_DATABASE: game-db
db2:
image: mongo
volumes:
- mongodata:/data/db2
ports:
- 27019:27017
restart: always
environment:
MONGO_INITDB_ROOT_DATABASE: score-db
volumes:
mongodata:
I do not know how to solve this problem.
I am beginner in Docker.
The problem here is with the network. Kindly understand that each container is a kind of a separate VM. Here, You are trying to connect to localhost. This will not work as each of the containers will resolve to it's own Loop back.
You can solve this in multiple ways:
Since all the containers are connected to the same docker network you can use container names to resolve respective ones. So here you can use db:27017 to connect to MongoDB.(Recommended)
Since you have port bonded all the containers you can use of the host machine instead of localhost. So if your host machine's private IP is 10.0.0.1 then use 10.0.0.1:27017 to connect to MongoDB.
Use host network, in this case, port binding instruction will be useless as it will be ignored and every service gets bonded automatically to their own port and you can use localhost to connect each of them (Not recommended)
References:
Networking overview
Use bridge networks
Networking in Compose
I have a Ubuntu 18.04 LTS vps in where I've installed and configured postgresql.
I can log in to the postgresql via command line. But I can not be able to establish a connection into my project.
But right after deployment of an Adonis project, It shoes me error message of below
error: error: password authentication failed for user "postgres"
Full Error is below:
error: error: password authentication failed for user "postgres"
0|server | at Connection.parseE (project_directory/node_modules/pg/lib/connection.js:614:13)
0|server | at Connection.parseMessage (project_directory/node_modules/pg/lib/connection.js:413:19)
0|server | at Socket.<anonymous> (project_directory/node_modules/pg/lib/connection.js:129:22)
0|server | at Socket.emit (events.js:315:20)
0|server | at addChunk (_stream_readable.js:295:12)
0|server | at readableAddChunk (_stream_readable.js:271:9)
0|server | at Socket.Readable.push (_stream_readable.js:212:10)
0|server | at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
0|server | From previous event:
0|server | at Client_PG.acquireRawConnection (project_directory/node_modules/knex/lib/dialects/postgres/index.js:147:12)
0|server | at create (project_directory/node_modules/knex/lib/client.js:280:23)
0|server | at project_directory/node_modules/tarn/lib/Pool.js:315:34
0|server | at Object.tryPromise (project_directory/node_modules/tarn/lib/utils.js:53:24)
0|server | at project_directory/node_modules/tarn/lib/Pool.js:315:17
0|server | at new Promise (<anonymous>)
0|server | at callbackOrPromise (project_directory/node_modules/tarn/lib/Pool.js:306:12)
0|server | at Pool._create (project_directory/node_modules/tarn/lib/Pool.js:236:9)
0|server | at Pool._doCreate (project_directory/node_modules/tarn/lib/Pool.js:208:36)
0|server | at Pool._tryAcquireOrCreate (project_directory/node_modules/tarn/lib/Pool.js:159:18)
0|server | at Pool.acquire (project_directory/node_modules/tarn/lib/Pool.js:85:14)
0|server | at project_directory/node_modules/knex/lib/client.js:335:26
0|server | From previous event:
0|server | at Client_PG.acquireConnection (project_directory/node_modules/knex/lib/client.js:334:34)
0|server | at Runner.ensureConnection (project_directory/node_modules/knex/lib/runner.js:228:24)
0|server | at Runner.run (project_directory/node_modules/knex/lib/runner.js:34:42)
0|server | at Builder.Target.then (project_directory/node_modules/knex/lib/interface.js:20:43) {
0|server | length: 104,
0|server | severity: 'FATAL',
0|server | code: '28P01',
0|server | detail: undefined,
0|server | hint: undefined,
0|server | position: undefined,
0|server | internalPosition: undefined,
0|server | internalQuery: undefined,
0|server | where: undefined,
0|server | schema: undefined,
0|server | table: undefined,
0|server | column: undefined,
0|server | dataType: undefined,
0|server | constraint: undefined,
0|server | file: 'auth.c',
0|server | line: '333',
0|server | routine: 'auth_failed'
0|server | }
Though I did some research and as per these instructions I updated the pg_hba.conf file. Here it is below:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 peer
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
Here is my project environemnt(.env) file
HOST=127.0.0.1
PORT=8989
NODE_ENV=development
APP_NAME=
APP_URL=http://${HOST}:${PORT}
CACHE_VIEWS=false
APP_KEY=my_app_key
DB_CONNECTION=pg
DB_HOST=127.0.0.1
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=my_db_pass
DB_DATABASE=my_db_name
... other credential goes here ....
Note: my_db_pass is my postgres username's password. I can successfully get logged in using this password in command-line.
Can anyone help me figuring out about what went wrong ?
I just changed this
let client = new Client({
user: process.env.USER,
host: process.env.HOST,
database: process.env.DATABASE,
password: process.env.PASSWORD,
port: process.env.DB_PORT,
});
to this
let client = new Client({
user: "postgres",
host: process.env.HOST,
database: process.env.DATABASE,
password: "aaaaa",
port: process.env.DB_PORT,
});
In server the process.env.USER is not my given username. IDK why but the value was changed.
I ran into the same issue. In my case, I added special characters in my password with escaping them.
https://docs.adonisjs.com/guides/environment-variables#escape-the--sign
Basically, change your user or username in .env.
username -> db_uername
user -> db_user
go in config/database.js
find PostgreSQL configuration and replace password value like this
password: "direct set your password",
and try I have same issue in Cpanel hosting and I try this method it's work