Definition
fsyncUnlockReduces the lock count on the server or cluster. To enable write operations, the lock count must be zero.
Starting in MongoDB 4.4.25, the
fsyncandfsyncUnlockcommands can run onmongosto lock and unlock a sharded cluster.Use this command to unblock writes after you finish a backup operation.
Important
Servers maintain an fsync lock count. The
fsynccommand with thelockfield set totrueincrements the lock count while thefsyncUnlockcommand decrements it. To enable writes on a locked server or cluster, call thefsyncUnlockcommand until the lock count reaches zero.fsyncUnlockis an administrative operation. Typically you will usefsyncUnlockfollowing a database backup operation.Tip
In the
mongoShell, this command can also be run through thedb.fsyncUnlock()helper method.Helper methods are convenient for
mongousers, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.To run the
fsyncUnlockcommand, use thedb.adminCommand()method:db.adminCommand( { fsyncUnlock: 1, comment: <any> } ) The
commentfield is optional and may contain a comment of any data type.The operation returns a document with the following fields:
FieldDescriptioninfoInformation on the status of the operation
lockCount(New in version 3.4)The number of locks remaining on the instance after the operation.
okThe status code.
Examples
Consider a situation where db.fsyncLock() has been issued two
times. The following fsyncUnlock operation reduces the
locks taken by db.fsyncLock() by 1:
db.adminCommand( { fsyncUnlock: 1 } )
The operation returns the following document:
{ "info" : "fsyncUnlock completed", "lockCount" : NumberLong(1), "ok" : 1 }
As the lockCount is greater than 0, the mongod instance
is locked against writes. To unlock the instance for writes, run the
unlock operation again:
db.adminCommand( { fsyncUnlock: 1 } )
The operation returns the following document:
{ "info" : "fsyncUnlock completed", "lockCount" : NumberLong(0), "ok" : 1 }
The mongod instance is unlocked for writes.