Articles → MONGODB → $Substrcp Aggregation Function In Mongodb

$Substrcp Aggregation Function In Mongodb






Purpose





Syntax


{ $substrCP: [ <string>, <start>, <length> ] }



Example




Picture showing the sample document collection




db.Employees.aggregate([
  {
    $project: {      
      name: { $substrCP: ["$firstname", 0, 2] }
    }
  }
])



Output


Picture showing the output of $substrcp aggregation function in mongodb



Posted By  -  Karan Gupta
 
Posted On  -  Monday, June 3, 2024

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250