General rule of thumb that I use is to do all formatting of the data at the application layer and not at the database.
That said, what you have tried is the first thing I found; and then I found this one as well
db.whois.find({ "source": { "$exists": true } }).forEach(function(doc) {
db.whois.update(
{ "_id": doc._id },
{ "$set": { "source": doc.source.toUpperCase() } }
);
});
Reference:
MongoDB – Update to upper case – Mkyong.com[
^]