How to Check Version of MongoDB
-
the
db.version()
Method in MongoDB -
the
mongod --version
Command in MongoDB -
the
mongo --version
Command in MongoDB -
Use the
mongo --help
Command in MongoDB -
Use the
mongo
Command in MongoDB -
the
buildInfo
Command in MongoDB
MongoDB is a well-known unstructured database management system that can handle massive volumes of data. It’s a document-oriented database system that belongs to the NoSQL family of databases (non-SQL).
The records and data are stored as documents that resemble JSON objects in appearance and functionality. MongoDB’s primary data unit is documented, a collection of key-value pairs.
For developers that want to deal with structured, semi-structured, or unstructured data in their applications, MongoDB is necessary. Those interested in big data analysis can also utilize MongoDB.
If your application’s data demands agility, scalability, and high performance, MongoDB is the best option. MongoDB can provide high-performance data storage even when distributed across several servers.
It may be used for various tasks, including real-time exploratory and predictive analytics and parallel data processing. If you’re unsure what version of MongoDB you’re using, there are six ways to find out.
Some of these check the version of your MongoDB server, while others check the version of your Mongo Shell. Let’s have a look in any case.
the db.version()
Method in MongoDB
If you’re already connected to MongoDB, you may verify the version with the db.version()
function. This function returns the mongod
or mongos
instance’s version.
The query for this method is given below.
db.version()
The result for the query mentioned above is shown below.
4.4.1
the mongod --version
Command in MongoDB
Check the MongoDB version using the mongod —version
command in a terminal window or Command Prompt.
The query for this method is given below.
mongod --version
The result for the query mentioned above is shown below.
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 haven’t added MongoDB to your PATH
, you must use the complete path.
The following command is given below.
"C:\Program Files\MongoDB\Server\4.4\bin\mongod.exe" --version
You will need to know the version before you can type the path, which is ironic! (Replace 4.4
with the MongoDB version you’re using.)
You might also use the file explorer to go to the folder, also disclosing the version number.
the mongo --version
Command in MongoDB
Run the mongo —version
command from a terminal window or Command Prompt if you require the mongo shell version.
The query for this method is given below.
mongo --version
The result for the query mentioned above is shown below.
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 query:
"C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe" --version
Use the mongo --help
Command in MongoDB
Running mongo —help
from a terminal window or Command Prompt is another way to get the mongo shell version.
The query for this method is given below.
mongo --help
The result for the query mentioned above is shown below.
MongoDB shell version v4.4.1
usage: mongo [options] [db address] [file names (ending in .js)]
db address can be:
...
Because the assistance list is pretty lengthy, it will not be displayed in its entirety here. Above the list is the MongoDB shell version.
Windows non-PATH query:
"C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe" --help"
Use the mongo
Command in MongoDB
When you connect to MongoDB using the mongo shell, you’ll see both Mongo and MongoDB server versions.
For example, to connect to MongoDB, open a terminal window or Command Prompt and type the following command.
mongo
You will see something like this when the above command is run.
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.
...
Typically, the message continues, but the mongo shell version and MongoDB server version are shown at the top (as shown here).
the buildInfo
Command in MongoDB
The buildInfo
command is an administrative command that returns the current mongods
build summary.
The query for this method is given below.
db.runCommand( { buildInfo: 1 } )
The result for the query mentioned above is shown below.
{
"version" : "4.4.1",
"gitVersion" : "ad91a93a5a31e175f5cbf8c69561e788bbc55ce1",
"modules" : [ ],
"allocator" : "system",
"javascriptEngine" : "mozjs",
"sysInfo" : "deprecated",
"versionArray" : [
4,
4,
1,
0
],
...
}
It contains much more information than only version information. However, version information is included in the version
field and the versionArray
field.
In this article, MongoDB has been explained and what it is, and who uses this database. Then the problem of finding the exact version was solved, and seven different methods to find out the exact version of MongoDB you are working on were discussed in detail.