How to append or prepend a value to a column in mongodb update

JavaScript |

7th May, 2023

Click here to share

To append a column to another and update the value using MongoDB you can follow these steps if you are on MongoDB compass

Open the shell command panel on the base of the MongoDB window called

 

type use <collection>

where <collection> is the name of your database without the angle brackets

 

the the code below

 

db.collection.aggregate(
    [
        { "$addFields": { 
            "name": { "$concat": [ "$firstName", " ", "$lastName" ] } 
        }},
        { "$out": <output collection name> }
    ]
)

 

UPDATE A COLUMN

 

Leave a Reply

RELATED POSTS


Total of 0 Comment