如何找到已安装 MongoDB 的确切版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38160412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:46:57  来源:igfitidea点击:

How to find the exact version of installed MongoDB

mongodb

提问by Ville Miekk-oja

I have mongoDB 3.2 installed locally for Windows 7. I would like to find out its specific version (like is it 3.2.1, or 3.2.3 or...). How could I find it? If I open the database shell (mongo.exe), I can see it outputs:

我在本地为 Windows 7 安装了 mongoDB 3.2。我想找出它的特定版本(比如它是 3.2.1、3.2.3 还是...)。我怎么能找到呢?如果我打开数据库外壳(mongo.exe),我可以看到它输出:

MongoDB shell version: 3.2.0

MongoDB 外壳版本:3.2.0

But that's just the shell version, and I'm not sure whether it's the same as my real database version.

但这只是shell版本,我不确定它是否与我的真实数据库版本相同。

回答by Punit Gupta

Just run your console and type:

只需运行您的控制台并输入:

db.version()

https://docs.mongodb.com/manual/reference/method/db.version/

https://docs.mongodb.com/manual/reference/method/db.version/

回答by ΦXoc? ? Пepeúpa ツ

Option1:

选项1:

Start the console and execute this:

启动控制台并执行:

db.version()

Option2:

选项2:

Open a shell console and do:

打开 shell 控制台并执行以下操作:

$ mongod --version

$ mongod --version

It will show you something like

它会告诉你类似的东西

$ mongod --version
db version v3.0.2

$ mongod --version
db 版本 v3.0.2

回答by Paul Hymanson

From the Java API:

来自 Java API:

Document result = mongoDatabase.runCommand(new Document("buildInfo", 1));
String version = (String) result.get("version");
List<Integer> versionArray = (List<Integer>) result.get("versionArray");

回答by tarun kumar143

To check mongodb version use the mongod command with --version option.

要检查 mongodb 版本,请使用带有 --version 选项的 mongod 命令。

To check MongoDB Server version, Open the command line via your terminal program and execute the following command:

要检查 MongoDB 服务器版本,请通过终端程序打开命令行并执行以下命令:

Path : C:\Program Files\MongoDB\Server\3.2\bin Open Cmd and execute the following command: mongod --version To Check MongoDB Shell version, Type:

路径:C:\Program Files\MongoDB\Server\3.2\bin 打开Cmd,执行如下命令: mongod --version 查看MongoDB Shell版本,输入:

mongo -version

mongo 版本

回答by Kalyan Halder Raaz

Sometimes you need to see version of mongodbafter making a connection from your project/application/code. In this case you can follow like this:

有时,您需要在从project/application/code建立连接后查看mongodb 的版本。在这种情况下,您可以按照以下方式操作:

 mongoose.connect(
    encodeURI(DB_URL), {
      keepAlive: true
    },
    (err) => {
      if (err) {
        console.log(err)
      }else{
           const con = new mongoose.mongo.Admin(mongoose.connection.db)
              con.buildInfo( (err, db) => {
              if(err){
                throw err
              }
             // see the db version
             console.log(db.version)
            })
      }
    }
  )

Hope this will be helpful for someone.

希望这对某人有帮助。