mongodb connection error with node and express - jhipster-registry

mongodb connection error with node and express.
The error:
at QueryReqWrap.onresolve [as oncomplete] (dns.js:206:19) {
errno: undefined,
code: 'ECONNREFUSED',
syscall: 'querySrv',
hostname: '_mongodb._tcp.clustr0-a1rol.mongodb.net'
}

Here are some possible issues with this case:
Check your IP address is whitelisted with your MongoDB client
Check your connection URI once again to check the possible error with that.
Please check this other problem and solution. link

I have faced the same issue, whatever I done is:
restart my node server.
change my database user.
change my network and waiting sometime.
then tried to connect.
this time mongo connection was fine.
N.B- you can check your connection URI too, if its ok. then try with a different network.

Related

Connection with MongoDB Cloud frequently fail with ESERVFAIL error

I have created a MongoDB Cloud Database to test my NodeJs Backend.
Ocassionally (probably the 70% of the time), I cant connect and the connect and the console throws the following error log:
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
Error: querySrv ESERVFAIL _mongodb._tcp.cluster0.u08yi.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (node:dns:213:19) {
errno: undefined,
code: 'ESERVFAIL',
syscall: 'querySrv',
hostname: '_mongodb._tcp.cluster0.u08yi.mongodb.net'
}
The weird thing is that I can connect sometimes. Is it because it is free and then it is prone to fail? It is getting frustrating since sometimes I have to keep updating my nodemon hoping for the ddbb to connect.
I already allowed my IP access.
Im using Mongoose and connecting this way:
mongoose.connect(`mongodb+srv://username:password#cluster0.u08yi.mongodb.net/mydatabase?retryWrites=true&w=majority`,(err)=>{
if(err) throw err;
console.log("MongoDB Connected Successfully");
})

Can't connect to mongoDB: Mongo error { Error: querySrv ENODATA

My set-up consists of Node.js on Express on the back-end connected to mongoDB through mongoose. When I start the server, I get this error:
Mongo error { Error: querySrv ENODATA `database_hostname`
at errnoException (dns.js:55:10)
at QueryReqWrap.onresolve [as oncomplete] (dns.js:243:19)
code: 'ENODATA',
errno: 'ENODATA',
syscall: 'querySrv',
hostname: `database_hostname` }
This results in me not being able to run my application on localhost due to it being constantly loaded.
At the same time connecting using MongoDB Compass works fine.
The database used to be working fine, but after I changed the location where I have been using it and created manually a new collection in Compass, which did not have a set-up locally, I started getting this error.
Cluster configuration:
SRV Record: off
Read Preference: Primary
SSL: System CA / Atlas Deployment
SSH Tunnel: None

ECONNRESET when connecting to ArangoDB cluster

I've set up an arangodb cluster within google cloud kubernetes. When I try to call methods using ArangoJS, it randomly throws following error.
Error: read ECONNRESET
at exports._errnoException (util.js:1020:11)
at TLSWrap.onread (net.js:580:26)
code: 'ECONNRESET',
errno: 'ECONNRESET',
syscall: 'read',
Also within the error there's a line with
authorizationError: 'SELF_SIGNED_CERT_IN_CHAIN',
It doesn't seems to occur when the server is already reading from the database, but when it reads from database after some idle period. (There's a load balancer in-between also)
Can anyone help me here?

MongoDB: \lib\server.js:235 process.nextTick getaddrinfo ENOTFOUND error

I'm a begginer in NodeJS and when i run node MainApp.js in console I get this error:
C:\Assigment 2 (NodeJS)\node_modules\mongodb\lib\server.js:235
process.nextTick(function() { throw err; })
^
Error: getaddrinfo ENOTFOUND . .:27017
at errnoException (dns.js:26:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26)
I don't know what this means. Inside MainApp I connect mongoose: mongoose.connect("./DataBase"); where DataBase is the folder where I run mongod --dbpath "C:\[...]\DataBase. The database server seems to start successfully, the console printing: [...] waiting for connections on port 27017.
server.js lines 231-236:
// Try to callback
try {
callback(err);
} catch(err) {
process.nextTick(function() { throw err; })
}
Package versions:
"express": "~4.13.1",
"mongodb": "~2.1.0",
"mongoose": "~4.3.1"
make sure that your database is up and running.
Go to your terminal and in your app directory run:
mongod
Then restart your node server and you should be good go
I do not understand the whole process yet, but I hope this answer will provide some insight:
It seems that running node or npm start without starting up the database returns this error.
If database is started, then changing
mongoose.connect("./DataBase"); (which previously caused the error)
to mongoose.connect('mongodb://localhost/database');fixes the issue.
Intuitively this seems to simply be the error MongoDB returns when it can't find the database used by the server, however this might not be the precise description of the issue.
If someone can provide further insight into the problem, such help would be appreciated.
I changed connection string from mongodb://localhost:27017/ to mongodb://127.0.0.1:27017/ and it worked.

SailsJS deployment to Heroku, connect to Mongolabs MongoDB

I am right now attempting my first Heroku deployment of a SailsJS API. My app uses SailsJS v0.11 andsails-mongo 0.11.2.
I have updated config/connections.js to include the connection information to MongoDB database I have hosted for free at Mongolab.
mongodb: {
adapter: 'sails-mongo',
url: "mongodb://db-user:password123#ds047812.mongolab.com:47812/testing-db"
}
Also updated config/models.js to point to that adapter.
module.exports.models = {
connection: 'mongodb',
migrate: 'safe'
};
This is basically all I have changed from running the code locally, when I deploy to Heroku the app crashes and I get this error...
/home/zacharyhustles/smallChangeAPI/node_modules/connect-mongo/lib/connect-mongo.js:186
throw err;
^
at Socket.emit (events.js:107:17)
2015-07-08T19:37:00.778316+00:00 app[web.1]:
at Socket.<anonymous> (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/connection.js:534:10)
Error: Error connecting to database: failed to connect to [localhost:27017]
How do I get rid of this, and make sure Sails does not try connecting to localhost db?
Ok, the problem was with storing sessions.
My solution was to setup a Redis database to store sessions.
In config/sessions.js make sure everything is commented out except for the method you want for session store.
Mine looked like this:
adapter: 'redis',
host: 'example.redistogo.com',
port: 1111,
db: '/redistogo',
pass: 'XXXXXYYYYYYXYXYXYYX',
This solved my posted problem, hope this helps another person out.