setVersion
Sets the currently active database version
Definition
setVersion sets the current active Version . This command is only persistent during a single client session and is not global.
The setVersion command has the following form:
{
"setVersion" : <number> or <string> or <date>
}
The command accepts the following fields:
Field | Type | Mandatory |
---|---|---|
setVersion | number or string or date | yes |
Usage
Use setVersion to set the active version of the database in your session. You can do this in one of 3 ways:
- If supplied with the string 'current', then setVersion sets your current version to always be the most recent version of the database. In this mode, you are able to do inserts, updates and deletes.
- If supplied with a numeric argument, setVersion sets your current version to that version number. See Working with versions for a discussion on how to determine the appropriate version.
- If supplied with a date, setVersion sets your current version to the version that was active at that time.
Output
The returned document contains a subset of the following fields:
Field | Type | Description |
---|---|---|
setVersion.ok | number | The status of the command. |
setVersion.response | string | The response message. |
setVersion.version | number | The version that has been set. |
Examples
Set the version to current
The following command will set the version to the version that is current:
mongo> db.runCommand({setVersion:'current'})
{
"ok" : 1,
"response" : "The version has been set to: 'current'",
"version" : NumberLong(10883850),
"status" : "current"
}
Set the version to a version number
The following command will set the version to 1,0010,010:
mongo> db.runCommand({setVersion:10010010})
{
"ok" : 1,
"response" : "The version has been set to: '10010010'",
"version" : NumberLong(10010010),
"status" : "userDefined"
}
Set the version to a datetime
In the following example, we set the version to the version that was current as of Feb-14th, 10am Zulu time:
mongo> db.runCommand({setVersion:new Date('2019-02-14T10:00:00Z')})
{
"ok" : 1,
"response" : "The version has been set to: '5045'",
"version" : NumberLong(5045),
"status" : "userDefined"
}```
Updated about 5 years ago
What’s Next