Navigation

setUserWriteBlockMode

Definition

Syntax

The setUserWriteBlockMode command has the following syntax:

db.adminCommand(
   {
      setUserWriteBlockMode: 1,
      global: <boolean>
   }
)

The command takes the following fields:

Field Type Description
setUserWriteBlockMode integer Set this field to 1.
global boolean Blocks writes on a cluster when set to true. To enable writes on a cluster, set global: false.

Required Access

To execute the setUserWriteBlockMode command, the user must have the :authaction:`setUserWriteBlockMode` privilege.

Example

  1. Enable user write block mode:

    db.adminCommand( {
       setUserWriteBlockMode: 1,
       global: true
    } )
    
  2. Add a record to the collection:

    db.names.insertOne( { name: "George Washington Cable" } )
    

    The server blocks the write because the user write block is enabled.

    Example Output:

    MongoServerError: User writes blocked
    
  3. Disable user write block mode:

    db.adminCommand( {
       setUserWriteBlockMode: 1,
       global: false
    } )
    
  4. Add a record to the collection:

    db.names.insertOne( { name: "George Washington Cable" } )
    

    The :method:`~db.collection.insertOne()` method writes to a collection. The server allows the write because the user write block is disabled.