getVersion

Get the current active database version

Definition

getVersion retrieves the active version for the current session. If no version has been set by the user using the setVersion command, the current version from the database will be returned.

The getVersion command has the following form:

db.runCommand({
    "getVersion" : <number>
})

The command accepts the following fields:

FieldTypeMandatory
getVersionnumberyes

Output

The returned document contains a subset of the following fields:

FieldTypeDescription
oknumberThe status of the command.
responsestringThe response message.
versionnumberThe version number which is current.
statusnumberThe status of the version, indicating if the version is the current version or set by the user.

Example

Version is current

The following command will get the current version :

> db.runCommand({getVersion:1});
{
	"ok" : 1,
	"response" : "The version is set to: 'current'",
	"version" : NumberLong(5045),
	"status" : "current"
}```

## Version has been set by the user:

```javascript
> db.runCommand({setVersion:2000});
{
	"ok" : 1,
	"response" : "The version has been set to: '2000'",
	"version" : NumberLong(2000),
	"status" : "userDefined"
}
> db.runCommand({getVersion:1});
{
	"ok" : 1,
	"response" : "The version is set to: '2000'",
	"version" : NumberLong(2000),
	"status" : "userDefined"
}

BulkLoad in progress:

> db.runCommand({getVersion:1});
{
	"ok" : 1,
	"response" : "The version is set to: '5046'",
	"version" : NumberLong(5046),
	"status" : "bulkLoad"
}

What’s Next