MongoDB聚合运算符:$toLower

MongoDB聚合运算符:$toLower

文章目录

$toLower聚合运算符用于将字符串转换为小写。

语法

js 复制代码
{ $toLower: <expression> }
  • <expression>为可被解析为字符串的表达式。
  • 如果参数解析为null,则返回空字符串""

使用

$toLower仅对ASCII字符串具有明确定义的行为。换而言之,对其他字符无效。

举例

角度的双曲正切

inventory集合中有下列文档:

json 复制代码
{ "_id" : 1, "item" : "ABC1", quarter: "13Q1", "description" : "PRODUCT 1" }
{ "_id" : 2, "item" : "abc2", quarter: "13Q4", "description" : "Product 2" }
{ "_id" : 3, "item" : "xyz1", quarter: "14Q2", "description" : null }

下面的聚合操作使用$toLower表达式将字段itemdescription的值转换为小写。

js 复制代码
db.inventory.aggregate(
   [
     {
       $project:
         {
           item: { $toLower: "$item" },
           description: { $toLower: "$description" }
         }
     }
   ]
)

执行的结果为:

json 复制代码
{ "_id" : 1, "item" : "abc1", "description" : "product 1" }
{ "_id" : 2, "item" : "abc2", "description" : "product 2" }
{ "_id" : 3, "item" : "xyz1", "description" : "" }
相关推荐
九河云34 分钟前
华为云 DRS 数据复制服务:数据库无缝迁移上云的零停机实践
大数据·数据库·华为云
姓蔡小朋友37 分钟前
MySQL多表查询
数据库·mysql
云飞云共享云桌面42 分钟前
SolidWorks服务器怎么实现研发软件多人共享、数据安全管理
java·linux·运维·服务器·数据库·自动化
Elastic 中国社区官方博客1 小时前
Elasticsearch:使用 ES|QL 与 dense_vector 字段
大数据·数据库·人工智能·sql·elasticsearch·搜索引擎·全文检索
Channing Lewis1 小时前
mysql.connector.errors.OperationalError: 1040 (08004): Too many connections
数据库·mysql·adb
数据知道1 小时前
一文掌握向量数据库Chroma的详细使用
数据库·python·向量数据库
虹科网络安全1 小时前
艾体宝洞察 | Redis vs Valkey:解决 ElastiCache 的无序扩张与资源效率问题
数据库·redis·spring
xu_ws1 小时前
2G服务器优化MySQL内存配置指南
数据库·mysql
TG:@yunlaoda360 云老大1 小时前
华为云国际站代理商的ESW主要有什么作用呢?
网络·数据库·华为云
漂亮的小碎步丶2 小时前
【8】分库分表与百亿级话单数据处理详解
数据库