Details
-
Improvement
-
Status: Closed
-
Major - P3
-
Resolution: Fixed
-
None
-
Fully Compatible
-
Query 12 (04/04/16)
Description
Syntax
{$strLenBytes: <expression>}
|
{$strLenCP: <expression>} // CP stands for UTF-8 'code points'. |
Examples
Input
{_id: 0, string: "cliché"} |
Pipeline
db.coll.aggregate([{
|
$project: {
|
byteLength: {$strLenBytes: "$string"}, |
cpLength: {$strLenCP: "$string"} |
}
|
}])
|
Output
{_id: 0, byteLength: 7, cpLength: 6}
|
Original Description
We need to determine string length in aggregation pipeline
eg:
db.kol.insert({"text": "abcde"}) |
db.kol.insert({"text": "ab"}) |
|
db.kol.aggregate({ $project: { "text_length": {$length: "$text" }}}) |
result:
{ "_id" : ObjectId("53d0c9bdc2644cdc0ab835f5"), "text_length" : 5 } |
{ "_id" : ObjectId("53d0c9c1c2644cdc0ab835f6"), "text_length" : 2 } |
Attachments
Issue Links
- is depended on by
-
CSHARP-1660 Add expressions to determine the length of a string
-
- Closed
-
- is documented by
-
DOCS-8709 Document $strLenBytes/$strLenCP
-
- Closed
-
- is duplicated by
-
SERVER-5319 provide strlen expression for $project
-
- Closed
-
- is related to
-
DRIVERS-297 Aggregation Framework Support for 3.4
-
- Closed
-