rollback

Rollback any current operations on the database

Definition

rollback rolls back the started database version to the previous valid version. All database changes made after the valid version are discarded without ever becoming visible.

rollback can only be executed when a new version has been started but not finalised.

❗️

Warning

When a rollback command is issued, all update, insert and delete operations will be blocked until rollback is complete.

The rollback command has the following syntax:

{
    "rollback" : 1
}

The command accepts the following fields:

FieldTypeMandatory
rollbacknumberyes

Output

The returned document contains a subset of the following fields:

FieldTypeDescription
oknumberThe status of the command.
versionarrayarray of {<databaseName> : <versionNumber>}.

Example

> db.runCommand({rollback:1});
{ "ok" : 1, "version" : [ { "guytest" : NumberLong(10883850) } ] }

In the other session, an update command reports a failure:

mongo> db.AAAProvenDocs01.update({},{$set:{dummy:1}},{multi:true});
WriteCommandError({
	"ok" : 0,
	"n" : 0,
	"nModified" : 0,
	"writeErrors" : [
		{
			"index" : 0,
			"code" : 50210,
			"errmsg" : "Update command interrupted"
		}
	]
})

🚧

Note

Rollback exists for the contingency in which a single long running transaction is blocking database operations by holding a lock on a new version. Unlike the rollback command in transactional databases, it does not abort the transaction in the current session - rather it aborts the currently running transaction that is holding the database global version lock. (see Locking and concurrency ).


What’s Next