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: |
539
539
- Description
540
540
541
541
* - :expression:`$getField`
542
-
543
542
- Returns the value of a specified field from a document.
544
543
You can use :expression:`$getField` to retrieve the value of
545
544
fields with names that contain periods (``.``) or start
@@ -551,12 +550,16 @@ content: |
551
550
- Returns a random float between 0 and 1
552
551
553
552
* - :expression:`$sampleRate`
554
-
555
553
- Randomly select documents at a given rate. Although the exact
556
554
number of documents selected varies on each run, the quantity
557
555
chosen approximates the sample rate expressed as a percentage
558
556
of the total number of documents.
559
557
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
+
560
563
---
561
564
ref : agg-operators-objects
562
565
content : |
Original file line number Diff line number Diff line change @@ -1475,6 +1475,7 @@ Alphabetical Listing of Expression Operators
1475
1475
/reference/operator/aggregation/toDate
1476
1476
/reference/operator/aggregation/toDecimal
1477
1477
/reference/operator/aggregation/toDouble
1478
+ /reference/operator/aggregation/toHashedIndexKey
1478
1479
/reference/operator/aggregation/toInt
1479
1480
/reference/operator/aggregation/toLong
1480
1481
/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