Skip to content

Commit 3f7919b

Browse files
author
Mohammad Hunan Chughtai
authored
(DOCSP-7890): x509 node snippet fixes (#582)
* (DOCSP-7890): added node x509 connection snippet * updated js file to add count documents * (DOCSP-7890): mv const collection var collection & added await to collection.countDocuments * (DOCSP-7890): fixed uri + passed in only sslKey and cert via client.pem
1 parent ca2cde8 commit 3f7919b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

source/includes/connection-snippets/x509-snippets/node-connection.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
const { MongoClient } = require('mongodb');
33
const fs = require('fs');
44

5-
const client = new MongoClient('mongodb+srv://<cluster-url>?authMechanism=MONGODB-X509&ssl=true', {
6-
sslCA: fs.readFileSync('/etc/certs/mongodb/ca.pem'),
7-
sslKey: fs.readFileSync('/etc/certs/mongodb/client.pem'),
8-
sslCert: fs.readFileSync('/etc/certs/mongodb/client.pem')
5+
const credentials = fs.readFileSync('/etc/certs/mongodb/client.pem');
6+
7+
const client = new MongoClient('mongodb+srv://<cluster-url>/test?authSource=$external&retryWrites=true&w=majority&authMechanism=MONGODB-X509', {
8+
sslKey: credentials,
9+
sslCert: credentials
910
});
1011

1112
async function run() {

0 commit comments

Comments
 (0)