Update MongoDB field using value of another field
Asked 07 September, 2021
Viewed 2K times
  • 59
Votes

In MongoDB, is it possible to update the value of a field using the value from another field? The equivalent SQL would be something like:

UPDATE Person SET Name = FirstName + ' ' + LastName

And the MongoDB pseudo-code would be:

db.person.update( {}, { $set : { name : firstName + ' ' + lastName } );

11 Answer