Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a document in Mongo database like below

{
"_id" : ObjectId("1234"),
"emailContacts":[
{
"emailPosition": 1,
"emailAddress": "100@qa.com"
}
]
}

I would like to update email address into upper case

What I have tried:

I have tried below scenario:

db.collection.update({"emailContacts.emailAddress":{"$exists": true},
{$set:"emailContacts.emailAddress": $toUpper:{"emailContacts.emailAddress"}},{multi: true}});

the above code is not working. can anyone suggest the best way to update email address.
Posted
Updated 21-Aug-19 1:07am

1 solution

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
JavaScript
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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900