I can connect to mongoDB database using mongoclient
const MongoClient = require("mongodb").MongoClient;
const fs = require('fs');
let connectionString = "mongodb://XXXX";
tls = '-----BEGIN CERTIFICATE-----
XXXX
-----END CERTIFICATE-----'
fs.writeFileSync('tls_certificate', tls)
let options = {
tls: true,
tlsCAFile: 'tls_certificate',
useUnifiedTopology: true
};
// connects to a MongoDB database
MongoClient.connect(connectionString, options, function (err, db) {
if (err) {
console.log(err);
} else {
// lists the databases that exist in the deployment
db.db('example').admin().listDatabases(function(err, dbs) {
console.log(dbs.databases);
db.close();
});
}
});
How can I do the same with mongoose package? I am mongoose package because it has this nice object orientedness and field validation features.
Also can you clear what is this pem file, ca file and all these things? I am confused.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…