Advertisement
nahuelbkn

PROD_updateNamesToUpperCase

Mar 2nd, 2022
999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var bulk = db.users.initializeOrderedBulkOp();
  2. var count = 0;
  3.  
  4. db.users.find({}).forEach(function(doc) {
  5.     bulk.find({ "_id": doc._id }).updateOne({
  6.         "$set": {
  7.             "last_name": doc.last_name.toUpperCase(),
  8.             "first_name": doc.first_name.toUpperCase()
  9.         }}
  10.     );
  11.    
  12.     count++;
  13.    
  14.     if ( count % 500 == 0 ) {
  15.         bulk.execute();
  16.         bulk = db.users.initializeOrderedBulkOp();
  17.         count = 0;
  18.     }
  19.    
  20. });
  21.  
  22. if ( count > 0 )
  23.     bulk.execute();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement