Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
¿Cambiar mayúsculas en mongo a camel casing?

Tengo una colección llamada Usuario, que contiene los campos firstName y secondName. Pero los datos están en mayúsculas.

 { firstName: 'FIDO', secondName: 'JOHN', ... }

Queria saber si es posible hacer el campo a camello caso.

 { firstName: 'Fido', secondName: 'John', ... }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puede utilizar una función auxiliar para obtener la respuesta deseada.

 function titleCase(str) { return str.toLowerCase().split(' ').map(function(word) { return word.replace(word[0], word[0].toUpperCase()); }).join(' '); } db.User.find().forEach(function(doc){ db.User.update( { "_id": doc._id }, { "$set": { "firstName": titleCase(doc.firstName) } } ); });
over 4 years ago · Santiago Trujillo Report

0

Ejecute una operación de actualización con canalización agregada de la siguiente manera:

 const titleCase = key => ({ $concat: [ { $toUpper: { $substrCP: [`$${key}`,0,1] } }, { $toLower: { $substrCP: [ `$${key}`, 1, { $subtract: [ { $strLenCP: `$${key}` }, 1 ] } ] } } ] }); db.User.updateMany( {}, [ { $set: { firstName: titleCase('firstName'), secondName: titleCase('secondName') } } ] )

Parque infantil Mongo

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!