Update MongoDB collection using $toLower

后端 未结 6 1089
盖世英雄少女心
盖世英雄少女心 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 06:02

    Very similar solution but this worked me in new mongo 3.2 Execute the following in Mongo Shell or equivalent DB tools like MongoChef!

    db.tag.find({hashtag :{ $exists:true}}).forEach(
     function(e) {
       e.hashtag = e.hashtag.toLowerCase();
       db.tag.save(e);
    });
    

提交回复
热议问题