EZ

Eduzan

Learning Hub

Back to NOSQL

Scalar Functions

Published 2025-12-09

NoSQL

Description: Scalar functions in NoSQL databases perform operations on individual values and return a single result.

1. UPPER and LOWER

  • Description: Converts a string to upper or lower case respectively.
  • Example (MongoDB using $toUpper and $toLower in aggregation):
db.names.aggregate([{$project: {nameUpper: {$toUpper: "$name"}, nameLower: {$toLower: "$name"}}}]);

Converts the name field of each document to upper and lower case.

2. LENGTH (String Length)

  • Description: Returns the length of a string.
  • Example (MongoDB) :
db.names.aggregate([{$project: {nameLength: {$strLenCP: "$name"}}}]);

Calculates the length of the name field for each document.

3. ROUND

  • Description: Rounds a number to the nearest integer or specified decimal place.
  • Example (MongoDB) :
db.finances.aggregate([{$project: {roundedValue: {$round: ["$amount", 2]}}}]);

Rounds the amount field to two decimal places.