$toHashedIndexKey (aggregation)
定義
$toHashedIndexKey
Computes and returns the hash value of the input expression using the same hash function that MongoDB uses to create a hashed index. A hash function maps a key or string to a fixed-size numeric value.
注意
Unlike hashed indexes, the
$toHashedIndexKey
aggregation operator does ではない account for collation. This means the operator can produce a hash that does not match that of a hashed index based on the same data.
構文
$toHashedIndexKey
の構文は次のとおりです。
{ $toHashedIndexKey: <key or string to hash> }
例
You can use $toHashedIndexKey
to compute the hashed value of a
string in an aggregation pipeline. This example computes the hashed
value of the string "string to hash"
:
db.aggregate( [ { $documents: [ { val: "string to hash" } ] }, { $addFields: { hashedVal: { $toHashedIndexKey: "$val" } } } ] )
出力例:
[ { val: 'string to hash', hashedVal: Long("763543691661428748") } ]