How to get mongodb version from mongoose

前端 未结 3 1227
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-02 16:01

Simple, with the mongo cli:

db.version ()

How can I do the same with mongoose? How can I send a custom command?

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-02 16:34

    Try this one, it will give you the verion of both MongoDB and Mongoose

    async function run() {
        var admin = new mongoose.mongo.Admin(mongoose.connection.db);
        admin.buildInfo(function (err, info) {
           console.log(`mongodb: ${info.version}`);
           console.log(`mongoose: ${mongoose.version}`);
        });
    }
    
    mongoose.connect(process.env.MONGO_URI, {
            useNewUrlParser: true,
            useUnifiedTopology: true
        })
        .then(() => {
            console.log('MongoDB connected');
            run();
        })
        .catch(error => {
            console.log(error);
        });
    

提交回复
热议问题