Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
393 views
in Technique[技术] by (71.8m points)

node.js - How to connect to mongoDB using mongoose

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...