説明
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.
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の 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" } )
次のドキュメントが コレクションに存在する場合、 _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] | コレクションにすでにデータが含まれている場合は、コレクションをシャードする前に、 シャード キー に ハッシュされたインデックス を作成する必要があります。 空のコレクションの場合、MongoDB はsh.shardCollection()の一部としてインデックスを作成します。 |