Given a collection of user details, write mongo query to increase the age by 20% for documents where age exists.

AnswerBot
3mo

Mongo query to increase age by 20% for documents with age field

  • Use $exists operator to filter documents with age field

  • Use $mul operator to increase age by 20%

  • Example: db.users.updateMany({ age: { $exi...read more

Rajeev Kumar Singh
3mo
works at
db.user.updateMany( {age: {$exists: true}}, [{$set: {age: {$multiply: ["$age", 1.2]}}}] );
Help your peers!
Add answer anonymously...
Unico Connect Backend Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter