How to get mongodb version from mongoose

前端 未结 3 1215
佛祖请我去吃肉
佛祖请我去吃肉 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:54

    You can query the buildInfo directly from your Mongoose connection.

    var mongoose = require('mongoose');
    
    mongoose.connect('mongodb://localhost/test', function(err) {
        mongoose.db.command({ buildInfo: 1 }, function (err, info) {
            console.log(info.version);
        });
    });
    

    https://docs.mongodb.com/manual/reference/command/buildInfo/#dbcmd.buildInfo

提交回复
热议问题