本文介绍了将mongo中的大写字母更改为驼色大写字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为User的集合,其中包含字段firstName和secondName.但是数据用大写字母表示.
I have a collection named User, which contains the the fields firstName and secondName. But the data is in capital letters.
{
firstName: 'FIDO',
secondName: 'JOHN',
...
}
我想知道是否有可能将田野变成骆驼案.
I wanted to know whether it is possible to make the field to camel case.
{
firstName: 'Fido',
secondName: 'John',
...
}
推荐答案
您可以使用助手功能来获得所需的答案.
You can use a helper function to get your desired answer.
function titleCase(str) {
return str.toLowerCase().split(' ').map(function(word) {
return word.replace(word[0], word[0].toUpperCase());
}).join(' ');
}
db.User.find().forEach(function(doc){
db.User.update(
{ "_id": doc._id },
{ "$set": { "firstName": titleCase(doc.firstName) } }
);
});
这篇关于将mongo中的大写字母更改为驼色大写字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!