$toHashedIndexKey(聚合)
定义
语法
$toHashedIndexKey
具有以下语法
{ $toHashedIndexKey: <key or string to hash> }
示例
您可以使用 $toHashedIndexKey
计算聚合管道中字符串的哈希值。此示例计算字符串 "string to hash"
的哈希值。
db.aggregate( [ { $documents: [ { val: "string to hash" } ] }, { $addFields: { hashedVal: { $toHashedIndexKey: "$val" } } } ] )
示例输出
[ { val: 'string to hash', hashedVal: Long("763543691661428748") } ]