[CSHARP-1660] Add expressions to determine the length of a string Created: 10/May/16  Updated: 27/May/22  Resolved: 23/Aug/16

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: None
Fix Version/s: 2.4

Type: Improvement Priority: Major - P3
Reporter: Rathi Gnanasekaran Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-14670 Add expressions to determine the leng... Closed
Epic Link: MongoDB 3.4
Server Compat: 3.3

 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 }



 Comments   
Comment by Githook User [ 29/Sep/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1660: added support for both bytes and codepoint variant.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/b0717496ef80d52d725efeadf2c348535d4aec63

Comment by Githook User [ 29/Sep/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1660: added support for $strLenCP.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/90689e40604e0f0f9435a119f01883c42eefd9bb

Comment by Githook User [ 24/Sep/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1660: added support for both bytes and codepoint variant.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/b0717496ef80d52d725efeadf2c348535d4aec63

Comment by Githook User [ 24/Sep/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1660: added support for $strLenCP.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/90689e40604e0f0f9435a119f01883c42eefd9bb

Comment by Githook User [ 21/Sep/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1660: added support for both bytes and codepoint variant.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/820c44ee62f7a6a3da4f9b36586ec9fba94aa316

Comment by Githook User [ 21/Sep/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1660: added support for $strLenCP.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/9d868617176bbb30eb1c38aff485e3f40edccd74

Comment by Githook User [ 16/Sep/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1660: added support for both bytes and codepoint variant.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/cba85cd493ea5cee90990f8ad65fc9a8ba1eb97b

Comment by Githook User [ 16/Sep/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1660: added support for $strLenCP.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/d592ca7cf8b670dfbff01465deddd9ba76a8c2fb

Comment by Githook User [ 09/Sep/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1660: added support for both bytes and codepoint variant.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/df9f865a08c6a66a19997de7da415461ab42c45a

Comment by Githook User [ 31/Aug/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1660: added support for $strLenCP.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/0bba3e85839f82ca95d5de5262d6f3c7f0b8555d

Comment by Githook User [ 29/Aug/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1660: added support for $strLenCP.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/5a66bf4d6152128965402f2532b82297b959400d

Comment by Githook User [ 23/Aug/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1660: added support for $strLenCP.
Branch: v2.4.x
https://github.com/mongodb/mongo-csharp-driver/commit/f49a5b75d1d75b296f23fea6aaec6587ad662e64

Generated at Wed Feb 07 21:40:18 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.