[SERVER-51486] Need of toTitleize Aggregation Pipeline Operator Created: 11/Oct/20  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Akansha kumari Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 0
Labels: qexec-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Execution
Backwards Compatibility: Minor Change
Participants:

 Description   

Currently there isn't existing Aggregate Pipeline operator which returns a string in Tileize format. There are some use-case where we need the result in Titleize format. And it will be useful if we add that operator. 

Kindly let me know if you also think there is a need for toTileize operator...



 Comments   
Comment by Akansha kumari [ 21/Oct/20 ]

Hi Asya, This would work.

Thank-you for the response.

I guess we can close this ticket then.

Comment by Asya Kamsky [ 20/Oct/20 ]

There are a few other ways to do it ...

db.title.aggregate({$set:{titlized:{$reduce:{
    input:{$range:[1,{$strLenCP:"$text"}]},
    initialValue:{$toUpper:{$substr:["$text",0,1]}},
    in:{$let:{
       vars:{
          char:{$substr:["$text", "$$this", 1]}, 
          prevChar: {$substr:["$text", {$add:[-1,"$$this"]}, 1]}
       }, 
       in: {$concat:[
            "$$value", {$cond:{if:{$in:[ "$$prevChar", [" ","_", "-"] ]},then: {$toUpper:"$$char"}, else: "$$char"}}]}
    }}
}}}})
 

This will treat " ", "_", and "-" as character indicating next letter should be capitalized.

Comment by Akansha kumari [ 20/Oct/20 ]

Yes Asya, Correct! It will capitalise the first letter of every word (space separated) of a string.

 

Comment by Asya Kamsky [ 20/Oct/20 ]

The above syntax might be simpler if we supported some sort of string "join" like SERVER-15697 (if it took a separator on which to join the array of words).

 

Comment by Asya Kamsky [ 20/Oct/20 ]

I'm not sure what this would do. Is this meant to take a string of words (space separated) and capitalize first letter of every word?

input: "kids went to the store" output: "Kids Went To The Store"?
(Like https://apidock.com/rails/String/titleize or https://docs.python.org/3/library/stdtypes.html?highlight=title#str.title)

db.title.find()
{ "_id" : ObjectId("5f8eff87e3bf9919fec309f6"), "text" : "man from the boondocks" }
{ "_id" : ObjectId("5f8eff94e3bf9919fec309f7"), "text" : "x-men: the last stand" }
db.title.aggregate({$set:{titlized:{$substr:[{$reduce:{input:{$split:["$text"," "]}, initialValue:"", in:{$concat:["$$value"," ",{$toUpper:{$substr:["$$this",0,1]}},{$substr:["$$this",1,{$strLenCP:"$$this"}]}]}}},1,{$strLenCP:"$text"}]}}})
{ "_id" : ObjectId("5f8eff87e3bf9919fec309f6"), "text" : "man from the boondocks", "titlized" : "Man From The Boondocks" }
{ "_id" : ObjectId("5f8eff94e3bf9919fec309f7"), "text" : "x-men: the last stand", "titlized" : "X-men: The Last Stand" }

I'm not sure this is a common enough functionality to have a named expression for...

Comment by Akansha kumari [ 14/Oct/20 ]

Hi Edwin, I would like to work on the feature I requested. 

Comment by Edwin Zhou [ 14/Oct/20 ]

Thank you for your feature request. We're assigning this ticket to the appropriate team to be evaluated against our currently planned work. Updates will be posted on this ticket as they happen.

Best,

Edwin

Generated at Thu Feb 08 05:25:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.