1
- ==========================
1
+ =======================
2
2
$strLenCP (aggregation)
3
- ==========================
3
+ =======================
4
4
5
5
.. default-domain:: mongodb
6
6
@@ -24,12 +24,12 @@ Definition
24
24
syntax <agg-quick-ref-operator-expressions>`:
25
25
26
26
.. code-block:: javascript
27
+ :copyable: false
27
28
28
29
{ $strLenCP: <string expression> }
29
30
30
31
The argument can be any valid :ref:`expression
31
- <aggregation-expressions>` as long as it resolves to an string. For
32
- more information on expressions, see :ref:`aggregation-expressions`.
32
+ <aggregation-expressions>` that resolves to a string.
33
33
34
34
.. include:: /includes/extracts/agg-expression-null-operand-strLenCP.rst
35
35
@@ -66,7 +66,7 @@ Behavior
66
66
67
67
The :expression:`$strLenCP` operator counts the number of code points
68
68
in the specified string. This behavior differs from the
69
- :expression:`$strLenBytes` operator which counts the number of bytes in
69
+ :expression:`$strLenBytes` operator that counts the number of bytes in
70
70
the string, where each character uses between one and four bytes.
71
71
72
72
Example
@@ -75,51 +75,51 @@ Example
75
75
Single-Byte and Multibyte Character Set
76
76
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77
77
78
- Create a ``food`` collection with the following documents :
78
+ Create a ``food`` collection:
79
79
80
80
.. code-block:: javascript
81
81
82
- db.food.insertMany(
83
- [
84
- { "_id" : 1, "name" : "apple" },
85
- { "_id" : 2, "name" : "banana" },
86
- { "_id" : 3, "name" : "éclair" },
87
- { "_id" : 4, "name" : "hamburger" },
88
- { "_id" : 5, "name" : "jalapeño" },
89
- { "_id" : 6, "name" : "pizza" },
90
- { "_id" : 7, "name" : "tacos" },
91
- { "_id" : 8, "name" : "寿司" }
92
- ]
93
- )
94
-
95
-
96
- The following operation uses the ``$strLenCP`` operator to calculate
82
+ db.food.insertMany( [
83
+ { _id: 1, name: "apple" },
84
+ { _id: 2, name: "banana" },
85
+ { _id: 3, name: "éclair" },
86
+ { _id: 4, name: "hamburger" },
87
+ { _id: 5, name: "jalapeño" },
88
+ { _id: 6, name: "pizza" },
89
+ { _id: 7, name: "tacos" },
90
+ { _id: 8, name: "寿司" }
91
+ ] )
92
+
93
+ The following example uses the ``$strLenCP`` operator to calculate
97
94
the ``length`` of each ``name`` value:
98
95
99
96
.. code-block:: javascript
100
97
101
- db.food.aggregate(
102
- [
103
- {
98
+ db.food.aggregate( [
99
+ {
104
100
$project: {
105
- " name" : 1,
106
- " length" : { $strLenCP: "$name" }
101
+ name: 1,
102
+ length: { $strLenCP: "$name" }
107
103
}
108
- }
109
- ]
110
- )
104
+ }
105
+ ] )
111
106
112
- The operation returns the following results :
107
+ Example output :
113
108
114
109
.. code-block:: javascript
115
-
116
- { "_id" : 1, "name" : "apple", "length" : 5 }
117
- { "_id" : 2, "name" : "banana", "length" : 6 }
118
- { "_id" : 3, "name" : "éclair", "length" : 6 }
119
- { "_id" : 4, "name" : "hamburger", "length" : 9 }
120
- { "_id" : 5, "name" : "jalapeño", "length" : 8 }
121
- { "_id" : 6, "name" : "pizza", "length" : 5 }
122
- { "_id" : 7, "name" : "tacos", "length" : 5 }
123
- { "_id" : 8, "name" : "寿司", "length" : 2 }
124
-
125
- .. seealso:: :expression:`$strLenBytes`
110
+ :copyable: false
111
+
112
+ [
113
+ { _id: 1, name: 'apple', length: 5 },
114
+ { _id: 2, name: 'banana', length: 6 },
115
+ { _id: 3, name: 'éclair', length: 6 },
116
+ { _id: 4, name: 'hamburger', length: 9 },
117
+ { _id: 5, name: 'jalapeño', length: 8 },
118
+ { _id: 6, name: 'pizza', length: 5 },
119
+ { _id: 7, name: 'tacos', length: 5 },
120
+ { _id: 8, name: '寿司', length: 2 }
121
+ ]
122
+
123
+ .. seealso::
124
+
125
+ :expression:`$strLenBytes`
0 commit comments