Database Manual / Sharding / Reference

Operational Restrictions in Sharded Clusters分片集群中的操作限制

Sharding Operational Restrictions分片操作限制

Operations Unavailable in Sharded Environments分片化环境中不可用的操作

$where does not permit references to the db object from the $where function. This is uncommon in un-sharded collections.$where不允许从$where函数引用db对象。这在非分片集合中并不常见。

Single Document Modification Operations in Sharded Collections分片集合中的单文档修改操作

To use updateOne() and deleteOne() operations for a sharded collection that specify the multi: false or justOne option:要对指定multi:falsejustOne选项的分片集合使用updateOne()deleteOne()操作:

  • If you only target one shard, you can use a partial shard key in the query specification or,如果你只针对一个分片,你可以在查询规范中使用部分分片键,或者,
  • You can provide the shard key or the _id field in the query specification.您可以在查询规范中提供分片键_id字段。

To use findOneAndUpdate() with a sharded collection, your query filter must include an equality condition on the shard key to compare the key and value in either of these formats:要将findOneAndUpdate()与分片集合一起使用,查询筛选器必须在分片键上包含相等条件,以便以以下任一格式比较键和值:

{ key: value }
{ key: { $eq: value } }

Unique Indexes in Sharded Collections分片集合中的唯一索引

MongoDB does not support unique indexes across shards, except when the unique index contains the full shard key as a prefix of the index. In these situations MongoDB will enforce uniqueness across the full key, not a single field.MongoDB不支持跨分片的唯一索引,除非唯一索引包含完整的分片键作为索引的前缀。在这些情况下,MongoDB将强制整个键的唯一性,而不是单个字段。

Tip

See: 请参阅:

Unique Constraints on Arbitrary Fields for an alternate approach.任意字段的唯一约束,用于替代方法。

Consistent Indexes一致的索引

MongoDB does not guarantee consistent indexes across shards. Index creation during addShard operations or chunk migrations may not propagate to new shards.MongoDB不保证跨分片的索引一致。在addShard操作或块迁移期间创建索引可能不会传播到新的分片。

To check a sharded cluster for consistent indexes, use the checkMetadataConsistency command:要检查分片集群的索引是否一致,请使用checkMetadataConsistency命令:

db.runCommand( {
checkMetadataConsistency: 1,
checkIndexes: true
} )

Write Concern for DDL Operations编写DDL操作问题

On a sharded cluster, DDL (Data Definition Language) operations run with write concern "majority". 在分片集群上,DDL(数据定义语言)操作以写关注"majority"运行。If you specify a different write concern, the operation overrides the provided write concern with "majority".如果指定了不同的写入关注,则该操作将用"majority"覆盖提供的写入关注。