File tree Expand file tree Collapse file tree 3 files changed +65
-2
lines changed Expand file tree Collapse file tree 3 files changed +65
-2
lines changed Original file line number Diff line number Diff line change @@ -539,7 +539,6 @@ content: |
539539 - Description
540540
541541 * - :expression:`$getField`
542-
543542 - Returns the value of a specified field from a document.
544543 You can use :expression:`$getField` to retrieve the value of
545544 fields with names that contain periods (``.``) or start
@@ -551,12 +550,16 @@ content: |
551550 - Returns a random float between 0 and 1
552551
553552 * - :expression:`$sampleRate`
554-
555553 - Randomly select documents at a given rate. Although the exact
556554 number of documents selected varies on each run, the quantity
557555 chosen approximates the sample rate expressed as a percentage
558556 of the total number of documents.
559557
558+ * - :expression:`$toHashedIndexKey`
559+ - Computes and returns the hash of the input expression using
560+ the same hash function that MongoDB uses to create a hashed
561+ index.
562+
560563 ---
561564ref : agg-operators-objects
562565content : |
Original file line number Diff line number Diff line change @@ -1475,6 +1475,7 @@ Alphabetical Listing of Expression Operators
14751475 /reference/operator/aggregation/toDate
14761476 /reference/operator/aggregation/toDecimal
14771477 /reference/operator/aggregation/toDouble
1478+ /reference/operator/aggregation/toHashedIndexKey
14781479 /reference/operator/aggregation/toInt
14791480 /reference/operator/aggregation/toLong
14801481 /reference/operator/aggregation/toObjectId
Original file line number Diff line number Diff line change 1+ ===============================
2+ $toHashedIndexKey (aggregation)
3+ ===============================
4+
5+ .. default-domain:: mongodb
6+
7+ .. contents:: On this page
8+ :local:
9+ :backlinks: none
10+ :depth: 1
11+ :class: singlecol
12+
13+ Definition
14+ ----------
15+
16+ .. expression:: $toHashedIndexKey
17+
18+ Computes and returns the hash value of the input expression using
19+ the same hash function that MongoDB uses to create a hashed index.
20+ A hash function maps a key or string to a fixed-size numeric
21+ value.
22+
23+ Syntax
24+ ------
25+
26+ ``$toHashedIndexKey`` has the following syntax:
27+
28+ .. code-block:: javascript
29+
30+ { $toHashedIndexKey: <key or string to hash> }
31+
32+ Example
33+ -------
34+
35+ You can use ``$toHashedIndexKey`` to compute the hashed value of a
36+ string in an aggregation pipeline. This example computes the hashed
37+ value of the string ``"string to hash"``:
38+
39+ .. code-block:: javascript
40+ :emphasize-lines: 4
41+
42+ db.aggregate(
43+ [
44+ { $documents: [ { val: "string to hash" } ] },
45+ { $addFields: { hashedVal: { $toHashedIndexKey: "$val" } } }
46+ ]
47+ )
48+
49+ Example output:
50+
51+ .. code-block:: javascript
52+ :copyable: false
53+
54+ [ { val: 'string to hash', hashedVal: Long("763543691661428748") } ]
55+
56+ Learn More
57+ ----------
58+
59+ - :method:`convertShardKeyToHashed()`
You can’t perform that action at this time.
0 commit comments