对于 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: The fully managed service for MongoDB deployments in the cloud

注意

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.

Consider a sharded collection that uses a hashed shard key [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()的一部分。
给本页内容打分

在此页面上