How to modify a every field on every document(row) in a MongoDB Collection to Lowercase/Uppercase

The first parameter after the find is the query, in this case {} indicates an empty query (do the following statements on all rows [documents] in the collection.

db.yourCollectionName.find( {}, { 'desiredFieldname': 1 } ).forEach(function(doc) {
      { _id: doc._id},
      { $set : { 'desiredFieldname' : doc.desiredFieldname.toLowerCase() } },
      { multi: true }

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts




All Rights Reserved Theme by 404 THEME.