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

convertShardKeyToHashed (método 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.

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

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

Observação

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

  • 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

Consider a sharded collection that uses a hashed shard key [1]

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

Se o seguinte documento existir na collection, o valor hash do campo _id será usado para distribuir o documento:

{
_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] Se a collection já contiver dados, você deverá criar um índice hash na chave do shard antes de fragmentar a collection. Para uma collection vazia, o MongoDB cria o índice como parte do sh.shardCollection().
Avalie esta página