Node.js do not connecting to MongoDB 6 - node.js

I have:
MongoDB version 6.0.1
Mongosh version 1.6.0
mongodb version 5.0.1 (Node.js driver)
Node.js version 16.16.0
When I using mongosh with link "mongodb://127.0.0.1:27017/xxx" it connecting to database (localy). But when I try to connect from Node.js with link "mongodb://127.0.0.1:27017/xxx" it do not connection. In database module the code
const client = new MongoClient(url, { useUnifiedTopology: true, useNewUrlParser: true });
client.connect((err) => {...});
Even it do not throw an error by timeout connection.

Related

MongoDB: command SON([('listCollections', 1), ('cursor', {})]) on namespace cuckoo.$cmd failed: Unsupported OP_QUERY command

I am trying to connect cuckoo and mongodb. I download mongodb and cuckoo. When I write cuckoo command to start cuckoo it gives error:
2023-01-09 04:21:22,515 [cuckoo] CRITICAL: CuckooCriticalError: Unable to connect to MongoDB: command SON([('listCollections', 1), ('cursor', {})]) on namespace cuckoo.$cmd failed: Unsupported OP_QUERY command: listCollections. The client driver may require an upgrade. For more details see https://dochub.mongodb.org/core/legacy-opcode-removal. In order to operate Cuckoo as per your configuration, a running MongoDB server is required.
I am using ubuntu 22.04.
mongod --version
db version v6.0.3 Build Info: { "version": "6.0.3", "gitVersion": "f803681c3ae19817d31958965850193de067c516", "openSSLVersion": "OpenSSL 3.0.2 15 Mar 2022", "modules": [], "allocator": "tcmalloc", "environment": { "distmod": "ubuntu2204", "distarch": "x86_64", "target_arch": "x86_64" } }
I am trying to reinstall mongodb and chown command but it does not work.
From the Wire Protocol documentation:
OP_QUERY
Deprecated in MongoDB 5.0. Removed in MongoDB 5.1.
So you will need to either:
upgrade the driver used by Cuckoo to one compatible with the version of MongoDB you are running
install MongoDB version 5.0 or older

Can't connect node to SQL Server

I'm trying to connect a node app with a SQL Server database, but I keep getting this error:
Error while connecting database: ConnectionError:
Error: [Microsoft][SQL Server Native Client 11.0]SQL Server Network Interfaces: Connection string is not valid [87].
Error: [Microsoft][SQL Server Native Client 11.0]Login timeout expired
Error: [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
I use the node package mssql with driver msnodesqlv8, and this is my db config:
const dbConfig = {
user: "user",
password: "password",
driver: 'msnodesqlv8',
server: 'DESKTOP-QG3R51Q',
database: 'WeighingScales',
options: {
instanceName: 'SQLEXPRESS',
trustedConnection: true,
}
};

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!

Can't connect to Mongo Atlas getaddrinfo ENOTFOUND [cluster name]

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.

Azure + Cassandra certified by Bitnami VM + nodejs app: Cannot connect to cassandra from remote app

Using datastax nodejs driver: 'cassandra-driver'
Connecting to database in my nodejs app server backend as:
const cassandra = require('cassandra-driver');
const client = new cassandra.Client({ contactPoints: [ '${azure_vm_ip}' ] });
Output log:
{ [Error: All host(s) tried for query failed. First host tried, azure_vm_ip:9042: Error: Connection timeout. See innerErrors.]
innerErrors:
{ 'azure_vm_ip:9042':
{ [Error: Connection timeout]
message: 'Connection timeout',
info: 'Cassandra Driver Error' } },
info: 'Represents an error when a query cannot be performed because no host is available or could be reached by the driver.',
message: 'All host(s) tried for query failed. First host tried, azure_vm_ip:9042: Error: Connection timeout. See innerErrors.' }
Questions:
Should I edit something on the default cassandra.yaml file? If
so, what?
Should I do something with firewall? If so, what?
Should I pass in more options in new cassandra.Client({
contactPoints: [ '${azure_vm_ip}' ] })? If so, What?
Make sure you have set rule for 9042 port in NSG. Also check whether the same port is in listening mode inside the VM.

Resources