Add row to whole column in mongodb

I would like to add a row to all the mongo collection column values.

Sort of

 db.testcoll.update({},{$set:{column1 : "prependstring"+ column1}});

Is there something like this?

+4
source share
1 answer

This can be achieved using the operator $concatin the aggregation pipeline.

db.testcoll.aggregate([{
  $project: {
    column1: {
      $concat: ['prependstring', '$column1']
    }
  }
}]);

As indicated in the official MongoDB docs ( here ), the operator $concatonly works with strings.

+4
source

All Articles