Update MongoDB collection using $toLower

后端 未结 6 1101
盖世英雄少女心
盖世英雄少女心 2020-12-01 05:34

I have an existing MongoDB collection containing user names. The user names contain both lower case and upper case letters.

I want to update all the user names so th

6条回答
  •  孤街浪徒
    2020-12-01 05:58

    With the accepted solution I know its very trivial to do the same for an array of elements, just in case

    db.myCollection.find().forEach(
       function(e) {
          for(var i = 0; i < e.articles.length; i++) { 
              e.articles[i] = e.articles[i].toLowerCase(); 
          }
          db.myCollection.save(e); 
       }
    )
    

提交回复
热议问题