I would like to prepend a string to all values of a mongo collection's column.
Something like
db.testcoll.update({},{$set:{column1 : "prependstring"+ column1}});
Is there something like this ?
That can be achieved using the $concat
operator in an aggregation pipeline.
db.testcoll.aggregate([{
$project: {
column1: {
$concat: ['prependstring', '$column1']
}
}
}]);
As specified in the official MongoDB docs (here) the $concat
operator only works with strings.