MongoDB query to capitalise first letter in existing database

感情迁移 提交于 2019-12-02 13:10:01

it may not be the best solution. the only hiccup in below suggestion is to get "3" of $substr:["$name1",1,3] dynamically. but gives you a start?

db.toupper.aggregate([{$project:{name:{$concat:[{$toUpper:{$substr:["$name1",0,1]}},{$substr:["$name1",1,**3**]}]}}}])

below is the result

 db.toupper.find()

 "_id" : ObjectId("5767ca0badb381a5cc0d19cd"), "name1" : "lean" }
 "_id" : ObjectId("5767ca3aadb381a5cc0d19ce"), "name1" : "lean" }

 db.toupper.aggregate([{$project:{name:{$concat:[{$toUpper:{$substr:["$name1",0,1]}},{$substr:["$name1",1,3]}]}}}])

 "_id" : ObjectId("5767ca0badb381a5cc0d19cd"), "name" : "Lean" }
 "_id" : ObjectId("5767ca3aadb381a5cc0d19ce"), "name" : "Lean" }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!