Can't connect to Mongo Atlas getaddrinfo ENOTFOUND [cluster name] - node.js

Using Botkit to create slack bot but can't connect to Mongo Atlas for storage. Nodejs backend. Using Botkit-storage-mongo
Code:
var Botkit = require('botkit');
var BotkitStorage = require('botkit-storage-mongo');
storage = BotkitStorage({ mongoUri: `mongodb+srv://<username>:<password>#<clustername>/test?retryWrites=true&w=majority`})
When I run the code I get this error:
UnhandledPromiseRejectionWarning: Error: MongoError: failed to connect to server [<cluster_name>] on first connect [Error: getaddrinfo ENOTFOUND <cluster_name>
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26) {
name: 'MongoError',
message: 'getaddrinfo ENOTFOUND <cluster_name>'
}]
Dependencies:
"dependencies": {
"botkit": "0.6.21",
"botkit-storage-mongo": "1.0.7",
"mongodb": "^3.5.0"
}
In Mongo Atlas,
my IP address is whitelisted.
Also tested allowing all IPs: 0.0.0.0/0.
Any ideas as to why I cannot connect?

This issue had nothing to do with botkit.
Needed to update connection driver version in mongo atlas dashboard.
Was Node.js 3.0 or later driver version. When I changed that to the Node.js 2.2.12 or later version, that connection string worked.

Related

Unable to connect mongoDB server with my node.js file, getting MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 constantly

mongod database process running
Local server connected to mongoDB compass
created mongooseTut Folder
npm init
mongoose and node installed
when i try to connect to server by writing node .\index.js, it thorws the error shown in picture, i.e.-MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
P.S.: Have already tried each and every solution mentioned in all relevant replies on stackoverflow.
Tried connecting node.js to mongoDb server and got error MongooseServerSelectionError: connect ECONNREFUSED ::1:27017

when I try to connect to mongodb I got these error

(node:9804) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
(Use node --trace-deprecation ... to show where the warning was created)
Connection errorMongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
name: 'MongoNetworkError'
}]
keep your mongodb compass open then try running the code from your IDE.

Database is not running in mongodb atlas due to unhandled promise exception

My code is running fine in localhost with no warnings but when I'm changing my connection string to the string provided by mongodb atlas, following errors are showing which you can see in the below pic and my browser keeps circulating plz guide me what I'm doing wrong
(node:13700) DeprecationWarning: 'open()' is deprecated in mongoose >=
4.11.0,
use 'openUri() instead, or set the 'useMongoClient' option if using 'connect()' or 'createConnection()'. See
http://mongoosejs.com/docs/4.x/docs/connections.html#use-mongo-client
(Use 'node --trace-deprecation... to show where the warning was
created)
Server started on port 3000
Error [MongoError]: failed to connect to server [undefined:27017] on first connect [Error: getaddrinfo ENOTFOUND undefined
at GetAddrInfoReqwrap.onlookup [as oncomplete] (dns.js:67:26) {}] name: 'MongoError'
at Pool. (C:\Users\Umer\Desktop\node\Alhamdulillah, complete webapp\All Validations Completed\node_modules\mongodb-core\lib\topologies\server.js: 336:35)
at Pool.emit (events.js:315 :20) at Connection.
(C:\Users\Umer\Desktop\node\Alhamdulillah, complet e webapp\A11
Validations Completed\node_modules\mongodb-core\lib\connection\poo1
Lis:280:12)
screenshot
According to the problem that you're facing, it is because you're coding the deprecated method of connecting to the MongoDB.
Your database.js file seems okay but I would suggest that you use dotenv and not a separate file for your secrets
But in your app.js file, kindly completely change the way you're connecting to MongoDB.
const config = require('./config/database')
const options = {useUnifiedTopology: true, useNewUrlParser: true}
mongoose.connect(config.mongoURI, options).then(
()=> console.log('connected to mongodb'),
(reason)=> console.error(`Error: ${reason}`)
)
// All of your other code ahead.
Happy Coding!

Error: Failed to connect to MongoDB. Are you sure your configured Mongo instance is running? When lifting sails

Hi guys im receiving an error
Error: Failed to connect to MongoDB. Are you sure your configured Mongo instance is running? Error details: { [MongoError: failed to connect to server on first connect] name: 'MongoError', message: 'failed to connect to server on first connect' }
I'm using a previous version of Sails since that its the version that they are currently using
Sails ~0.12.4
nodejs -v 4.2.6
npm -v 3.5.2
error: A hook (`orm`) failed to load!
error: Error: Failed to connect to MongoDB. Are you sure your configured Mongo instance is running?
Error details:{ [MongoError: failed to connect to server [192.168.2.45:27017] on first connect] name: 'MongoError',
failed to connect to server [192.168.2.45:27017] on first connect]
name: 'MongoError', message: 'failed to connect to server [192.168.2.45:27017] on first connect' }
My config/connection.js looks like this
module.exports.connections = {
localDiskDb: {
adapter: 'sails-disk'
},
mongodbServer: {
adapter: 'sails-mongo',
host: '192.168.2.45',
port: 27017,
user : 'dbAdmin',
password : 'hiveslab',
database: 'sauce_db'
},
};
I'm stuck on this for a day and I'm pretty much of a newbie here. Hopefully you guys can lead me to the right resolution. Thank you in advance have a good day.

getaddrinfo ENOTFOUND while connecting to SQL Server from Node.js

I am trying to connect to my SQL Server from Node.js and I am getting this exception:
ERROR: Failed to connect to WAMG9120116\SQLEXPRESS:1433 - getaddrinfo ENOTFOUND WAMG9120116\SQLEXPRESS.
Below is the configuration.
# DATABASE
DATABASE_NAME=AeroPresentationApi
DATABASE_HOST=WAMG9120116\SQLEXPRESS
DATABASE_PORT=1433
DATABASE_USERNAME=XXXX
DATABASE_PASSWORD=XXXXXX
RUN_MIGRATIONS_ON_STARTUP=true
We are connecting to DB via this:-
const sequelize = new Sequelize(
databaseConfig.database,
databaseConfig.username,
databaseConfig.password,
databaseConfig,
);
Can anyone tell me what is going on ?
NOTE: I was able to connect to SQL Server from SSMS using User Name and Password.

Resources