MongoDB Update to upper case
By:Roy.LiuLast updated:2019-08-17
A document, and you want to update all the ‘source’ values to UPPERCASE.
whois.json
"_id" : NumberLong(1),
"country" : "au",
"source" : "apnic"
"_id" : NumberLong(2),
"country" : "cn",
"source" : "apnic"
"_id" : NumberLong(3),
"country" : "us",
"source" : "arin"
Solution
No sure if there is any ready function, but you can write a script to update the value to uppercase :
db.whois.find({ "source": { "$exists": true } }).forEach(function(doc) { db.whois.update( { "_id": doc._id }, { "$set": { "source": doc.source.toUpperCase() } } ); });
Output
whois.json
"_id" : NumberLong(1),
"country" : "au",
"source" : "APNIC",
"_id" : NumberLong(2),
"country" : "cn",
"source" : "APNIC",
"_id" : NumberLong(3),
"country" : "us",
"source" : "ARIN",
Done.
From:一号门
COMMENTS