7 Ways to Check your MongoDB Version

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

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

The db.version() Method

If you’re 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’re 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’re on Windows and you haven’t added MongoDB to your PATH, you’ll 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 write the path! (You’ll need to replace 4.4 with the your MongoDB version).

You could alternatively navigate to the folder via the file explorer – a process which will also reveal the version number.

The mongo --version Command

If you need the mongo shell version, you can run the mongo --version command from a Terminal window or Command Prompt.

Example

mongo --version

Result:

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

Windows non-PATH example:

"C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe" --version

The mongo --help Command

Another way to get the mongo shell version 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] [db address] [file names (ending in .js)]
db address can be:
...

The help list is quite long, so I won’t output it all here. The MongoDB shell version is listed at the top.

Windows non-PATH example:

"C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe" --help

The mongo Command

Simply connecting to MongoDB via the mongo shell will result in both the mongo shell version and the MongoDB server version being displayed.

For example, opening a Terminal window or Command Prompt, and entering the following command, connects to MongoDB:

mongo

Once it connects, 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 on, but the mongo shell version and the MongoDB server version are listed near the top (as shown here).

The buildInfo Command

The buildInfo command is an administrative command which 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 a lot more than the version info, but version information is included in two fields: the version field and the versionArray field.

Via the MongoDB Compass GUI

If you use MongoDB Compass, you can find the MongoDB edition listed in the sidebar (at least, that’s where it’s located at the time this article was written).

Example:

Screenshot of MongoDB Compass