7 Ways to Check your MongoDB Version – Database.Guide

If you’re

wondering which version of MongoDB you’re running, here are 7 ways you can use to check.

Actually, some of these check the version of the MongoDB server and others check the version of your mongo shell. In any case, let’s take a look.

The db.version() method If you are already connected to MongoDB, you can use the db.version() method to check the version.

This method returns the version of the

mongod or mongos instance. Example: db.version() Result: 4.4.1 The mongod -version command

If you are not connected to MongoDB, you can open a Terminal window or command prompt and run

mongod -version. Example:

mongod

-version

Result

: db version v4.4.1 Build Info: { “version”: “4.4.1

“, “gitVersion”: “ad91a93a5a31e175f5cbf8c69561e788bbc55ce1”, “modules”: [], “allocator”: “system”, “environment”: { “distarch”

:

“x86_64”, “target_arch”: “x86_64” } } If you

are on Windows and have not added MongoDB to your PATH, you will need to use the full path

.

Like this

: “C:\Program Files\MongoDB\Server\4.4\bin\mongod.exe” -version

Ironically, you’ll need to know the version before you can type the path! (You will need to replace 4.4 with the MongoDB version.)

Alternatively, you can navigate to the folder through the file explorer, a process that will also reveal the version number.

The mongo -version command If you need the shell version of mongo

, you can run the mongo -version command from a Terminal window or a command prompt

.

Example

of mongo -version

Result

: MongoDB shell version v4.4.1 Build information: { “version”: “4.4.1”, “gitVersion”: “ad91a93a5a31e175f5cbf8c69561e788bbc55ce1”, “modules”: [], “allocator”: “system”, “environment”: { “distarch”: “x86_64”, “target_arch”: “x86_64” } }

Non-PATH Windows example:

“C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe” -version The mongo -help command Another way to get the shell version of mongo

is to run mongo -help from a Terminal window or command prompt. Example mongo -help

Result: MongoDB shell version v4.4.1 Usage: Mongo [options] [database address] [file names (ending in .js)] The database address can be

:

The help list is pretty long, so I won’t show it all here. The MongoDB shell version appears at the top.

Non-PATH Windows example

: “C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe” -help The mongo

command

Simply connecting to MongoDB via the mongo shell will display both the mongo shell version and the MongoDB server version.

For example, when you open a Terminal window or a command prompt, and enter the following command

, you connect to MongoDB:

mongo

Once you connect, you should see something like this

: MongoDB shell version v4.4.1 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { “id” : UUID(“8f03a0d8-7079-4884-bf2c-6a67b832d1a9”) } MongoDB server version: 4.4.1 Welcome to the MongoDB shell. …

The message usually continues, but the mongo shell version and MongoDB server version are listed near the top (as shown here).

The buildInfo

command The buildInfo

command

is an administrative command that returns a build summary for the current mongod

. Example: db.runCommand( { buildInfo: 1 } ) Result: { “version” : “4.4.1”, “gitVersion” : “ad91a93a5a31e175f5cbf8c69561e788bbc55ce1”, “modules” : [ ], “allocator” : “system”, “javascriptEngine” : “mozjs”, “sysInfo” : “deprecated”, “versionArray”

:

[ 4, 4, 1, 0 ], … }

It provides much more than version information, but version information is included in two fields: the version field and the versionArray field.

Through the MongoDB Compass graphical user interface If you use MongoDB Compass, you can find the MongoDB edition

listed in the sidebar (at least, that’s where you are at the time this article was written).

Example:

Screenshot of MongoDB Compass