Para agentes de IA: um índice de documentação está disponível em https://www.mongodb.com/pt-br/docs/llms.txt — as versões de markdown de todas as páginas estão disponíveis anexando .md a qualquer caminho de URL.
Menu Docs

setDefaultRWConcern (comando de banco de dados)

setDefaultRWConcern

The setDefaultRWConcern administrative command sets the global default read or write concern configuration for a replica set or sharded cluster. setDefaultRWConcern must be run against the admin database.

Esse comando está disponível em implantações hospedadas nos seguintes ambientes:

  • MongoDB Enterprise: a versão autogerenciada e baseada em assinatura do MongoDB

  • MongoDB Community: uma versão com código disponível, de uso gratuito e autogerenciada do MongoDB

O comando tem a seguinte sintaxe:

db.adminCommand(
{
setDefaultRWConcern : 1,
defaultReadConcern: { <read concern> },
defaultWriteConcern: { <write concern> },
writeConcern: { <write concern> },
comment: <any>
}
)

O comando utiliza os seguintes campos:

Campo
Tipo
Descrição

int

Defina como 1.

object

Documento que contém a configuração global de read concern. Especifique um objeto de read concern válido.

Omit this document to leave the current global read concern unmodified. If omitted, setDefaultRWConcern must specify defaultWriteConcern.

object

Documento que contém a configuração de write concern padrão global.

  • For the write concern w setting, setDefaultRWConcern supports all write concern values except w : 0.

  • For the write concern wtimeout setting, setDefaultRWConcern defaults to 0 if the setting is omitted. Operations block until the requested write concern is met. If specifying a global default wtimeout, ensure the value is large enough to allow write operations to achieve the requested write concern.

  • Para desmarcar o write concern configurado no momento, especifique um documento vazio {}.

Omit this document to leave the current global write concern unmodified. If omitted, setDefaultRWConcern must specify defaultReadConcern.

objeto

Optional. A document that specifies the write concern to be used by the setDefaultRWConcern command itself.

If omitted, setDefaultRWConcern uses the previously set global default write concern if one was configured.

comment

any

Opcional. Um comentário fornecido pelo usuário para anexar a este comando. Depois de definido, esse comentário aparece junto com os registros desse comando nos seguintes locais:

Um comentário pode ser qualquer tipo BSON válido (string, inteiro, objeto, array etc).

setDefaultRWConcern returns an object that contains the currently configured global default read and write concern. See getDefaultRWConcern for more complete documentation on the returned fields.

Observação

Exige featureCompatibilityVersion 4.4+

Each mongod in the replica set or sharded cluster must have featureCompatibilityVersion set to at least 4.4 to use setDefaultRWConcern.

A partir do MongoDB,5.0 uma vez que o Cluster Wide Write Concern (CWWC) é definido por meio do setDefaultRWConcern comando, o preocupação de gravação não pode ser desconfigurado.

O MongoDB só aplica o read ou write concern global padrão a operações que não especificam explicitamente um read ou write concern.

Se o MongoDB aplicar o read ou write concern padrão global a uma operação, essa operação se comportará como se esse read ou write concern fosse explicitamente especificado pelo cliente emissor.

Issue setDefaultRWConcern against the replica set primary. The primary replicates the new global default settings to the remaining members of the replica set. Secondaries which have not yet replicated the updated global default settings continue using their local 'stale' copy of the defaults.

Issue the setDefaultRWConcern command with a writeConcern of w : "majority" to ensure the command only returns after the changes have propagated to a majority of replica set members.

Issue the setDefaultRWConcern against a mongos in the cluster. The mongos persists the updated settings to the config server replica set (CSRS). Each mongos periodically issues a getDefaultRWConcern against the CSRS to refresh their local copy of the global settings. A mongos uses its local 'stale' copy of the global defaults during the time period between refreshes.

Issue the setDefaultRWConcern command with a writeConcern of w : "majority" to ensure the command only returns after the changes have propagated to a majority of CSRS members.

Quando um aplicativo emite uma operação no mongos sem especificar explicitamente uma configuração de read ou write concern, o mongos aplica a configuração padrão global correspondente.

The global default settings do not propagate to the individual shards. You cannot run setDefaultRWConcern against a shard.

Importante

setDefaultRWConcern exige featureCompatibilityVersion. 4.4+ Se você fizer o downgrade do featureCompatibilityVersion do sistema 4.4 de 4.2 para, todos os padrões da read e preocupação de gravação em todo o cluster serão perdidos, mas mongos as instâncias do poderão continuar aplicando os padrões por até 30 segundos.

O compartilhamento de comandos administrativos que executam operações de gravação no servidor de configuração, como os comandos enableSharding ou addShard, tem comportamento específico com configurações de write concern padrão global:

  • Os comandos usam o "majority" independentemente do write concern padrão global configurado.

  • Os comandos usam um wtimeout mínimo de 60000. Os comandos só usam o write concern padrão global wtimeout se ele for maior que 60000.

For replica sets or sharded clusters enforcing Authentication on Self-Managed Deployments, setDefaultRWConcern requires that the authenticated user have the setDefaultRWConcern privilege action.

The clusterManager built-in role provides the required privileges to run setDefaultRWConcern.

A seguinte operação define o write concern global para o seguinte:

db.adminCommand({
"setDefaultRWConcern" : 1,
"defaultWriteConcern" : {
"w" : 2
}
})

A operação retorna um documento semelhante ao seguinte:

{
"defaultWriteConcern" : {
"w" : 2
},
"updateOpTime" : Timestamp(1586290895, 1),
"updateWallClockTime" : ISODate("2020-04-07T20:21:41.849Z"),
"localUpdateWallClockTime" : ISODate("2020-04-07T20:21:41.862Z"),
"ok" : 1,
"$clusterTime" : { ... }
"operationTime" : Timestamp(1586290925, 1)
}

A operação a seguir define o read concern global como "majority":

db.adminCommand({
"setDefaultRWConcern" : 1,
"defaultReadConcern" : { "level" : "majority" }
})

A operação retorna um documento semelhante ao seguinte:

{
"defaultReadConcern" : {
"level" : "majority"
},
"updateOpTime" : Timestamp(1586290895, 1),
"updateWallClockTime" : ISODate("2020-04-07T20:21:41.849Z"),
"localUpdateWallClockTime" : ISODate("2020-04-07T20:21:41.862Z"),
"ok" : 1,
"$clusterTime" : { ... }
"operationTime" : Timestamp(1586290925, 1)
}

A operação a seguir define o read ou write concern padrão global para o seguinte:

db.adminCommand({
"setDefaultRWConcern" : 1,
"defaultWriteConcern" : {
"w" : 2
},
"defaultReadConcern" : { "level" : "majority" }
})

A operação retorna um documento semelhante ao seguinte:

"defaultWriteConcern" : {
"w" : 2
},
"defaultReadConcern" : {
"level" : "majority"
}

Você pode:

  • Desconfigure o read concern padrão global.

  • Desconfigure apenas o write concern padrão global se você ainda não o tiver definido.

Por exemplo, suponha que o read concern padrão global esteja configurado para level: "majority". Para desconfigurar o read concern padrão global, use um documento vazio {}:

db.adminCommand( {
"setDefaultRWConcern" : 1,
"defaultReadConcern" : {}
} )

A operação retorna um documento que indica que a operação foi bem-sucedida:

{
defaultReadConcern: { level: 'local' },
defaultWriteConcern: { w: 2, wtimeout: 0 },
updateOpTime: Timestamp({ t: 1656696934, i: 1 }),
updateWallClockTime: ISODate("2022-07-01T17:35:40.578Z"),
defaultWriteConcernSource: 'global',
defaultReadConcernSource: 'implicit',
localUpdateWallClockTime: ISODate("2022-07-01T17:35:40.578Z"),
ok: 1,
'$clusterTime': {
...
},
operationTime: Timestamp({ t: 1656632593, i: 1 })
}

Você só pode desconfigurar a definição do write concern padrão global se ainda não o tiver definido.

Para desconfigurar o write concern padrão global, use um documento vazio {}:

db.adminCommand( {
"setDefaultRWConcern" : 1,
"defaultWriteConcern" : {}
} )

Se o write concern padrão global:

  • For desconfigurado, a operação foi bem-sucedida.

  • Já estiver configurado, a operação retorna o seguinte erro.

MongoServerError: The global default write concern cannot be unset
once it is set.