如何查看 MongoDB 版本:命令行:使用 db.version() 命令。编程语言驱动程序:Python:print(client.server_info()["version"])Node.js:db.command({ version: 1 }, (err, result) => { console.log(result.version); });
如何查看 MongoDB 版本
要查看 MongoDB 数据库版本,有多种方法:
命令行方法:
mongo 命令启动 MongoDB shell。在 shell 中,键入以下命令:
db.version()
示例输出:
{
"version" : "4.4.21",
"gitVersion" : "677de5dea6f8fbd05213df45169d34dbc00e37e4",
"modules" : [],
"allocator" : "tcmalloc",
"javascriptEngine" : "mozjs"
}编程语言方法:
您可以使用编程语言中提供的驱动程序来获取版本信息:
Python:
import pymongo
client = pymongo.MongoClient("mongodb://localhost:27017")
print(client.server_info()["version"])Node.js:
const MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localhost:27017', (err, client) => {
const db = client.db('my_db');
db.command({ version: 1 }, (err, result) => {
console.log(result.version);
});
});返回的信息:
上述命令或函数将返回以下信息:
擎。