Update MongoDB field using value of another field
问题 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 } ); 回答1: The best way to do this is in version 4.2+ which allows using of aggregation pipeline in the update document and the updateOne, updateMany or update collection method. Note that the latter has