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

convertShardKeyToHashed(mongosh方法)

convertShardKeyToHashed(<Object>)

Returns the hashed value for the input. The convertShardKeyToHashed() method uses the same hashing function as the hashed index and can be used to see what the hashed value would be for a key.

此方法可用于以下环境中托管的部署:

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

注意

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

考虑使用哈希分片键的分片集合[1]

use test
db.orders.createIndex( { _id: "hashed" } )
sh.shardCollection( "test.orders", { _id : "hashed" } )

如果集合中存在以下文档,则使用_id字段的哈希值来分发该文档:

{
_id: ObjectId("5b2be413c06d924ab26ff9ca"),
"item" : "Chocolates",
"qty" : 25
}

To determine the hashed value of _id field used to distribute the document across the shards, you can use the convertShardKeyToHashed() method:

convertShardKeyToHashed( ObjectId("5b2be413c06d924ab26ff9ca") )
[1] 如果集合已包含数据,则必须在对集合进行分片之前对分片键创建哈希索引。 对于空的collection,MongoDB 会将索引创建为sh.shardCollection()的一部分。
给本页内容打分

在此页面上