MongoDB

Check the Version of Mongodb

MongoDB offers high-performance data storage when deployed over multiple servers. So, we need to identify the version of MongoDB running in the system when analyzing the reported problems. The version numbers which follow a semantic numbering scheme enable us in recognizing significant and minor changes. We can run the latest bug-free version by just updating the mongodb version which should be known. We have discussed some methods below which can be used to determine what version of MongoDB we are currently utilizing. Some of these techniques check the server version of the MongoDB, whereas others check the version of the Mongo shell.

How to Check the Version of Mongodb

The simplest approach to check the mongodb version is to run the “–help” option with the keyword “mongod”. We have opened the command line prompt in our system and placed the following command on the terminal screen of our system. The usage of this command helps us to get the flag that checks and outputs the current version of the mongodb application.

>mongod --help

The command of “mongod –help” listed all the general options as the output which might be used for running the mongodb in our operating system. Due to the lengthy list of options, we have just shown the option “–version”. The “–version” is the option which we use along with the mongodb shell to get the mongodb version.

Options:

–networkMessageCompressors arg (=snappy,zstd,zlib)

Comma-separated list of compressors to

use for network messages

General options:

-h [ –help ] Show this usage information

–version Show version information

Method # 1: Check the Mongodb Version with the Mongod Command

Now, we can use the –version flag to get the currently installed version of the mongodb. Here, we do not have a mongodb connection as the path is not given or the mongodb shell is not opened. When we are not connected to the mongodb then we can run the command below in the command prompt of our system. The “–version” flag is used with the “mongod” command.

>mongod -version

Once the “mongod –version” command is executed, the version of the mongodb is displayed as follows. It includes the current mongodb version and further build information on the mongodb application.

db version v6.0.3
Build Info: {
    "version": "6.0.3",
    "gitVersion": "f803681c3ae19817d31958965850193de067c516",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "windows",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

Method # 2: Check the Mongodb Version with the Mongo Command

Another approach to check the mongodb version is using the mongo method. In the command prompt, we have to use the keyword “mongo” which is the shell for running the mongodb queries. The mongo is employed with the option “–version” to check the mongodb shell version. The general representation of the mongo command to fetch the version is pasted below.

>mongo --version

The version of the mongo shell in our operating system is as follows:

mongo version v6.0.3
Build Info: {
    "version": "6.0.3",
    "gitVersion": "f803681c3ae19817d31958965850193de067c516",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "windows",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

Method # 3: Check the Mongodb Version with the File Path

The methods above are a way to obtain the mongodb version when the connection with the mongodb is not established. Here, we will fetch the version of our mongodb application by accomplishing the path of the file where the mongodb shell is located. To do this, we have launched the command prompt and with the “cd” command the full path of the mongodb shell is specified on the terminal. Then, press enter to execute the command.

>cd "C:\Program Files\MongoDB\Server\6.0\bin"

The file path of mongodb is given and the system successfully finds the specified path of the mongodb. After that, we have given the name of the application “mongod.exe” which also utilizes the “–version” option for getting the mongodb version.

C:\Program Files\MongoDB\Server\6.0\bin>mongod.exe --version

From the access of the file path of the mongodb, we have fetched the current mongodb version in the output represented below.

db version v6.0.3
Build Info: {
    "version": "6.0.3",
    "gitVersion": "f803681c3ae19817d31958965850193de067c516",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "windows",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

Method # 4: Check the Mongodb Version with the db.version() Command

All the aforementioned commands use the command prompt for getting the mongodb version. We also have another method for figuring out the mongodb version: by launching the mongodb shell. In this instance, we first made the connection. Then, run the following query in the mongodb shell. The “db” keyword is used with the “version()” method for generating the version of the mongodb used in the system.

>db.version()
[/c]
The query for checking the mongodb version displayed the numerical output which is the mongodb version downloaded from our system.
[cc lang="text" width="100%" height="100%" escaped="true" theme="blackboard" nowrap="0"]
'6.0.3'

Method # 5: Check the Mongodb Version with the BuildInfo Parameter Command

The last command line interface approach to get the mongodb version is using the “builInfo” method. A buildInfo command is a management tool that provides a build report for the current Mongod. We have employed the “runCommand()” query which takes the “buildInfo” command as a parameter. The buildInfo command is further set with the value “1” known as the true boolean value.

db.runCommand( { buildInfo: 1 } )

The output of the buildInfo command generates the version and the summary of the mongodb server.

{
  version: '6.0.3',
  gitVersion: 'f803681c3ae19817d31958965850193de067c516',
  targetMinOS: 'Windows 7/Windows Server 2008 R2',
  modules: [],
  allocator: 'tcmalloc',
  javascriptEngine: 'mozjs',
  sysInfo: 'deprecated',
  versionArray: [ 6, 0, 3, 0 ],
  openssl: { running: 'Windows SChannel' }

Method # 6: Check the Mongodb Version with the GUI Interface

The graphical user interface is the most appealing approach to checking the version of the mongodb. If the command line interface or any specific mongodb shell is not easy to use, then we can use the mongodb compass. The mongodb compass application is a GUI approach to getting the mongodb version. Firstly, we have launched the mongodb compass and built a connection with our existing local host. After that, we have three aligned dots on the left sidebar which on click displayed a few options. Among all the listed options, mouse over to the option “Connection info”. The screenshot of the mongodb compass is shown below which will be easy to follow the step for checking the mongodb version.

The “Connection info” generates the pop-up page where the information about the mongodb connection is given. On the pop-up page, we have a field “Edition”. Below the “Edition” field, the edition information of the mongodb is displayed as “MongoDB 6.0.3 Community”

Conclusion

The article is to check the version of mongodb. We have explored all the possible ways to get the mongodb version. A few methods are used to get the mongodb server version and other methods are for fetching the mongodb shell version. We first used the command line interface to check the mongodb version. Afterward, we have a mongodb compass GUI application were checking the mongodb version is easiest.

About the author

Saeed Raza

Hello geeks! I am here to guide you about your tech-related issues. My expertise revolves around Linux, Databases & Programming. Additionally, I am practicing law in Pakistan. Cheers to all of you.