草庐IT

MongoDB toLowerCase()

coder 2023-11-01 原文

我有一个名为 Profiles 的集合,其中包含一个名为 emails 的数组。

我想将数组中的所有电子邮件字符串更改为小写。

db.Profiles.update({"emails":/@/i}, {$set: {"emails" : emails.toLowerCase()}}})

错误:

1 月 29 日星期二 16:52:28 SyntaxError: missing ) after argument list (shell):1

我还发现了这个:

db.Profiles.find().forEach(
  function(e) {
    e.emails = e.emails.toLowerCase();
    db.Profiles.save(e);
  }
)

错误:

1 月 29 日星期二 16:51:41 TypeError:e.emails.toLowerCase 不是函数(shell):3

在此先感谢您的帮助。

最佳答案

您需要将电子邮件数组中的每个字符串小写。 string[] 中没有 toLowerCase 函数。

例子:

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

关于MongoDB toLowerCase(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14588022/

有关MongoDB toLowerCase()的更多相关文章

随机推荐