at QueryReqWrap.onresolve [as oncomplete] (dns.js:203:19) {
errno: 'ETIMEOUT',
code: 'ETIMEOUT',
syscall: 'queryTxt',
hostname: 'scheduly.1eln0.mongodb.net'
}
I’m facing the above connection Error while connecting with MongoDB Atlas. I’ve double-checked my username and password. I’ve whitelisted all the IP’s. I’m stuck in the middle of a project and cannot connect to the DB itself.
my connection strings are:
const mongoose = require("mongoose");
const mongodb = require("mongodb");
const uri = "mongodb+srv://ghulamghousdev:***********#scheduly.1eln0.mongodb.net/scheduly?retryWrites=true&w=majority
mongoose
.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("Connected");
})
.catch((err) => console.log(err));
The name of the Database on MongoDB atlas is scheduly.
Have you tried to add the ip of your VPS, host to the IP Whitelist of Network access?
You can see more details for that setting from here https://docs.atlas.mongodb.com/security-whitelist/
Related
Im trying to connect the database in my nodejs project.
I have created a mongo account and I have chosen Coonect your application to your cluster using MonngoDB's native drivers.
So the code to connect with the database is like this:
db.js
const mongoose = require("mongoose");
const connectDB = async () => {
const conn = await mongoose
.connect(
"mongodb+srv://username:<password>#cluster0.xk55obw.mongodb.net/?retryWrites=true&w=majority",
{
useNewUrlParser: true,
useUnifiedTopology: true,
}
)
.then(() => {
console.log("Database Connected");
})
.catch((err) => console.log(err));
};
module.exports = connectDB;
When I run the project in my terminal I get this error:
Error: querySrv ECONNREFUSED _mongodb._tcp.cluster0.xk55obw.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (node:dns:213:19) {
errno: undefined,
code: 'ECONNREFUSED',
syscall: 'querySrv',
hostname: '_mongodb._tcp.cluster0.xk55obw.mongodb.net'
}
The username and password are correct, I have checked them.
How can I solve this error?
I rented an EC2 instance of Ubuntu 16.xx on AWS and installed PostgreSQL on it. I created a database and table inside the PostgreSQL on EC2. Right now I am trying to connect to and get data from the database via a local Node.js project using knex.
I already enabled the inbound rule for port 5432 to IP from anywhere.
However, it returns error message as below:
Error: connect ECONNREFUSED 13.229.xxx.xxx:5432
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1142:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '13.229.xxx.xxx',
port: 5432
}
How am I gonna fix it? Do I need to install and implement a reversed proxy? If so, how do I set it up? I know there is RDS on AWS, but I need to use EC2 to implement it.
Here are some of my codes:
This is the knex setting, I have pg installed. The connection to a local database is successful. But when I switch the host to whether a public IP/ private IP/ ec2-13-229-xxx-xxx.ap-southeast-1.compute.amazonaws.com. They all return the above error message.
development: {
client: 'postgresql',
connection: {
host: '13.229.xxx.xxx',
database: 'project2',
user: 'postgres',
password: 'postgres',
port: 5432,
},
pool: {
min: 2,
max: 10,
},
migrations: {
tableName: 'knex_migrations',
},
},
This is the Node.js code that I used to connect to the server. A very simple one, just to test the connection.
const express = require('express');
const hbs = require('hbs');
const app = express();
const knexConfig = require('./knexfile')['development'];
const knex = require('knex')(knexConfig);
let query = knex.select('*').from('users');
query
.then((data) => {
console.log(data);
})
.catch((err) => console.log(err));
This is my firewall setting which is turned off
Also, I paused my Kaspersky.
This is my pg_hba.conf file
And I am not sure where to add the permission of my personal IP.
This issue was related to the pg_hba.conf being restricted to localhost only.
Additionally the postgres.conf needed to have listen_addresses = '*'.
By whitelisting outside access, it was possible to access the database.
Additional support from this article.
I have a node/express application that I am trying to connect to Mongodb Atlas using mongoose.
All of my code is identical to a previous app that I had connect to Atlas (which worked fine). When I run it on my work machine (Windows 10) everything works as expected. However, when I run it on my MacBook Pro (Mojave), the express app runs but the mongoose connection to Atlas throws the following error:
{ Error: queryTxt EBADNAME development-zv5hp.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:196:19)
errno: 'EBADNAME',
code: 'EBADNAME',
syscall: 'queryTxt',
hostname: 'development-zv5hp.mongodb.net' }
server.js
const express = require('express');
const mongoose = require('mongoose');
const app = express();
mongoose
.connect(
'mongodb+srv://client:<PASSWORD>#development-zv5hp.mongodb.net/shop',
{ useNewUrlParser: true }
)
.then(() => console.log('MongoDB Connected...'))
.catch(err => console.log(err));
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
What might be causing this issue?
I have checked the Atlas user and password and have whitelisted my IP (in fact whitelisted all IPs)
Using:
node v10.15.3
express v4.16.4
mongoose v5.5.1
Using Google's DNS server 8.8.8.8 and 8.8.4.4 can resolve this issue
please add autoIndex: false its working for me
mongoose
.connect(
'mongodb+srv://client:<PASSWORD>#development-zv5hp.mongodb.net/shop',
{autoIndex: false, useNewUrlParser: true }
This error is caused because the URI 'mongodb+srv://client:<PASSWORD>#development-zv5hp.mongodb.net/shop' that was passed to connect was unable to be resolved. Your DNS server does not know it and thus cannot resolve an IP. Hence ebadname.
change this like Addison mentioned
I am trying to connect to Atlas MongoDB with the following URI (provided by mongodb connection string )
module.exports = {
mongoURI:'mongodb+srv://<user>:<password>#cluster0-un6sk.mongodb.net/test?
retryWrites=true'
};
//connect to mongoose
mongoose
.connect(db)
.then( ()=>console.log('mongoDB connected'))
.catch(err => console.log(err));
I get the following error :
{ MongoNetworkError: connection 3 to cluster0-shard-00-00-un6sk.mongodb.net:27017 closed
at TLSSocket.<anonymous> (C:\Users\KARTIT Ismail\Desktop\devconnector\node_modules\mongodb-core\lib\connection\connection.js:352:9)
at Object.onceWrapper (events.js:273:13)
at TLSSocket.emit (events.js:182:13)
at _handle.close (net.js:606:12)
at TCP.done (_tls_wrap.js:386:7)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {} }
Make sure you have whitelisted your IP in the Atlas Control panel.
You can enter 0.0.0.0, if you wish to allow access from any host.
Then you can have a connection string like below:
var connectionString= 'mongodb://<username>:<password>#<clustername>/<dbname>?ssl=true&replicaSet=<replica setname>&authSource=admin';
var db = mongoose.connect(connectionString).catch((error) => { console.log(error); });
Whitelist the IP address, the best option allows access from any host, I believe everyone had installed mongoose, if not then use this command
npm i mongoose
First copy your application connection string from mongodb.com -> clusters->connect->connect your application
Now chose driver Node.js and version latest, now copy connection string.
Now connection.js
const mongoose = require('mongoose');
const conStr = 'mongodb+srv://lord:<password>#cluster5-eeev8.mongodb.net/test?retryWrites=true&w=majority'
const DB = conStr.replace(
'<password>',
myPass
);
const DB = conStr.replace(
'test',
myDatabaseName
);
//remember mongoose.connect() return promise
mongoose
.connect(DB, {
usedNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
})
.then((con) => {
console.log(con.connection);
console.log('DB connection successful');
});
In order to connect to Atlas MongoDB you should configure IP whitelist. Go to MongoDB Atlas website, login. Then, from the Clusters view, select the Security tab, then IP Whitelist. You will see an IP address. Click "Edit" Button then "current IP address". Press OK. Then restart your server.
Useful link : https://docs.atlas.mongodb.com/security-whitelist/#add-whitelist-entries
What version of mongoose are you using? Versions of mongoose less than version 5.0.15 doesn't appear to support the mongodb+srv:// server url.
The other common issue, is white listed IP addresses.
Source:
Error at connecting to MongoDb Atlas Server
Just whitelist the IP from the Atlas UI no need to restart the application.
I have created the cluster on the MongoDB Atlas and now trying to create the db connect to it using the connection string provided on the Atlas.
My Connection String on key.js file:
module.exports = {
//mongoURI: "mongodb://DEVELOPER:DEV1234#devconnector"
mongoURI:
"mongodb+srv://USERNAME:PWD#devconnector-7dd46.mongodb.net/test?retryWrites=true"
};
Server.js file, DB Connect:
const db = require("./config/keys").mongoURI;
mongoose
.connect(db, { useNewUrlParser: true })
.then(() => console.log("MongoDBConnected"))
.catch(err => console.log(err));
Error message:
{ Error: querySrv ESERVFAIL
_mongodb._tcp.devconnector-7dd46.mongodb.net
at errnoException (dns.js:55:10)
at QueryReqWrap.onresolve [as oncomplete] (dns.js:243:19) code: 'ESERVFAIL', errno: 'ESERVFAIL', syscall: 'querySrv', hostname:
'_mongodb._tcp.devconnector-7dd46.mongodb.net' }
Just to add, I am getting the same error message while on trying to connect with Atlas from the Compass. Any help would be appreciated!