Getting Data In

Unable to connect to Mongodb with SSL Certificate using MongoClient in Node Js Script

JiyaKhan1
New Member

Hi Team,

 

I'm trying to connect to MongoClient using Node Js Script.

While i'm passing the same certificate what we used earlier to connect through mongoose.connect . 
==========================================================
var MongoClient = require("mongodb").MongoClient,
 f = require('util').format,
 fs = require('fs');
 
const options = {
  server: {
  //sslValidate:true,
sslCA:fs.readFileSync("/etc/ssl/mongo-certs/client-combined.crt"),
  sslKey:fs.readFileSync("/etc/ssl/mongo-certs/client.key"),
  sslCert:fs.readFileSync("/etc/ssl/mongo-certs/client.crt"),
  }
}
MongoClient.connect("mongodb://username:password@hostname:27017/databasename?ssl=true&authSource=admin",options,
 
function (err,database) {
                console.log("Not Connected");
                if (err) return console.error(err);
 
                console.log("We are connected");
                        });
 
===================== Can you please help on this.. Log is saying as Below ============

I'm getting Below Error 

 

Labels (1)
0 Karma

JiyaKhan1
New Member

Hi Team,

 

I'm trying to connect to MongoClient using Node Js Script.

While i'm passing the same certificate what we used earlier to connect through mongoose.connect . 
==========================================================
var MongoClient = require("mongodb").MongoClient,
 f = require('util').format,
 fs = require('fs');

const options = {
  server: {
  //sslValidate:true,
sslCA:fs.readFileSync("/etc/ssl/mongo-certs/client-combined.crt"),
  sslKey:fs.readFileSync("/etc/ssl/mongo-certs/client.key"),
  sslCert:fs.readFileSync("/etc/ssl/mongo-certs/client.crt"),
  }
}
MongoClient.connect("mongodb://username:password@hostname:27017/databasename?ssl=true&authSource=admin",options,

function (err,database) {
                console.log("Not Connected");
                if (err) return console.error(err);

                console.log("We are connected");
                        });
 
===================== Can you please help on this.. Log is saying as Below ============
I'm getting Below Error 


2020-07-05T11:52:44.869+0000 I ACCESS [conn805] authenticate db: admin { authenticate: 1, user: "myassistroot", nonce: "5be2405f5a0d1eed", key: "d140b8834a2f96624991bfa9cdf911df", $db: "admin" }

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

Ready to make your IT operations smarter and more efficient? Discover how to automate Splunk alerts with Red ...