0
0
MongodbHow-ToBeginner · 3 min read

How to Check MongoDB Version Quickly and Easily

To check the MongoDB version, open your terminal or MongoDB shell and run the command mongod --version or mongo --version. Alternatively, inside the MongoDB shell, use db.version() to see the current server version.
📐

Syntax

There are two main ways to check the MongoDB version:

  • mongod --version: Shows the version of the MongoDB server daemon.
  • mongo --version: Shows the version of the MongoDB shell client.
  • db.version(): Run inside the MongoDB shell to get the server version.
bash
mongod --version

mongo --version

# Inside MongoDB shell
> db.version()
💻

Example

This example shows how to check the MongoDB server version from the command line and inside the MongoDB shell.

bash
# Check server version from terminal
mongod --version

# Start MongoDB shell
mongo

# Inside shell, check server version
> db.version()
Output
db version v6.0.5 MongoDB shell version v6.0.5 6.0.5
⚠️

Common Pitfalls

Some common mistakes when checking MongoDB version include:

  • Running mongod --version without proper permissions or without MongoDB installed.
  • Confusing the shell client version (mongo --version) with the server version.
  • Trying to run db.version() outside the MongoDB shell, which will cause errors.
bash
Wrong: Running db.version() in terminal
$ db.version()
-bash: db.version: command not found

Right: Run inside MongoDB shell
$ mongo
> db.version()
📊

Quick Reference

Summary of commands to check MongoDB version:

CommandDescription
mongod --versionShows MongoDB server daemon version
mongo --versionShows MongoDB shell client version
db.version()Shows MongoDB server version inside shell

Key Takeaways

Use mongod --version to check the MongoDB server version from the terminal.
Use mongo --version to check the MongoDB shell client version.
Inside the MongoDB shell, run db.version() to get the server version.
Do not run db.version() outside the MongoDB shell.
Ensure MongoDB is installed and accessible in your system PATH before running these commands.