一个文档,您想将所有“源”值更新为大写。
whois.json
{
"_id" : NumberLong(1),
"country" : "au",
"source" : "apnic"
}
{
"_id" : NumberLong(2),
"country" : "cn",
"source" : "apnic"
}
{
"_id" : NumberLong(3),
"country" : "us",
"source" : "arin"
}
解
不确定是否有任何就绪函数,但是您可以编写脚本将值更新为大写:
db.whois.find({ "source": { "$exists": true } }).forEach(function(doc) {
db.whois.update(
{ "_id": doc._id },
{ "$set": { "source": doc.source.toUpperCase() } }
);
});
输出量
whois.json
{
"_id" : NumberLong(1),
"country" : "au",
"source" : "APNIC",
}
{
"_id" : NumberLong(2),
"country" : "cn",
"source" : "APNIC",
}
{
"_id" : NumberLong(3),
"country" : "us",
"source" : "ARIN",
}
做完了
翻译自: https://mkyong.com/mongodb/mongodb-update-to-upper-case/