对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

getDefaultRWConcern(数据库命令)

getDefaultRWConcern

The getDefaultRWConcern administrative command retrieves the global default read or write concern settings.

此命令可用于以下环境中托管的部署:

  • MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务

注意

所有 MongoDB Atlas 集群都支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令

该命令采用以下形式:

db.adminCommand(
{
getDefaultRWConcern: 1 ,
inMemory: <boolean>,
comment: <any>
}
)

该命令具有以下字段:

字段
类型
说明

int

设置为 1

布尔

可选。

设置为 true 可返回全局默认读关注或写关注设置的内存中缓存副本。在对操作应用全局默认值时,实例会使用内存中副本。

设置为 false 可返回部署的全局默认读关注或写关注的磁盘副本。默认为 false

comment

any

可选。用户提供的待附加到该命令的注释。设置后,该注释将与该命令的记录一起出现在以下位置:

注释可以是任何有效的 BSON 类型(字符串、整型、对象、数组等)。

输出可能包括以下字段:

字段
类型
说明

object

全局默认的写关注配置。

如果部署没有全局默认写关注设置,则此字段不会出现在 getDefaultRWConcern 输出中。

object

全局默认的读关注配置。

如果部署没有全局默认读关注设置,则此字段不会出现在 getDefaultRWConcern 输出中。

字符串

默认写关注的来源。默认情况下,该值为 "implicit"。使用 setDefaultRWConcern 完成设置默认写关注后,该值即变为 "global"

字符串

默认读关注的来源。默认情况下,该值为 "implicit"。使用 setDefaultRWConcern 完成设置默认读关注后,该值即变为 "global"

时间戳

上次修改任何全局默认读关注或写关注设置时的操作时间戳。如果曾经为集群设置过默认值,则存在。

Date

管理员上次设置全局默认读关注或写关注的挂钟日期。此值仅供参考,不应用于任何近期比较。

Date

mongodmongos 上次更新其全局默认读关注和写关注设置的本地副本时的挂钟日期。此值仅供参考,不应用于任何近期比较。

注意

需要 featureCompatibilityVersion 4.4+

mongod副本集或分片集群中的每个 都必须将 featureCompatibilityVersion设立为至少 4.4才能使用getDefaultRWConcern 。如果您将部署的 featureCompatibilityVersion4.4 降级为4.2 ,则所有集群范围的读关注和写关注(write concern)默认值都将丢失,但mongos 实例可能会继续应用默认值长达30 秒。

You can issue getDefaultRWConcern against any data-bearing member of the replica set (i.e. not against an arbiter).

如果从节点尚未从主节点复制最新更改,则它可以返回全局默认设置的“过时”版本。

向集群中的 mongos 发出 setDefaultRWConcern

每个 mongos 都会定期刷新全局默认设置的本地副本。如果 mongos 在最近更新全局默认设置后尚未刷新其本地副本,或者从滞后的配置服务器从节点获取其设置,则它可以返回全局默认设置的“过时”版本。

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

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

The clusterManager or clusterMonitor built-in roles provides the required privileges to run getDefaultRWConcern.

以下操作检索 mongod 当前配置的全局默认读关注和写关注。

db.adminCommand({
"getDefaultRWConcern": 1
})

该操作返回类似于以下内容的输出:

{
"defaultWriteConcern" : {
"w" : "majority"
},
"defaultReadConcern" : {
"level" : "majority"
},
"defaultWriteConcernSource" : "global",
"defaultReadConcernSource" : "global",
"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)
}