I need equivalent mongo query to below SQL query:
Update tableName set tableName.col1 = tableName.col2
I need equivalent mongo query to below SQL query:
Update tableName set tableName.col1 = tableName.col2
Update: I had given incorrect solution earlier. As the answer is accepted, updating it with the right way
db.collectionName.find().snapshot().forEach(function (elem) {
db.collectionName.update({_id: elem._id}, {$set: {col2: elem.col1}});
}
);
Use normal update query along wiht $set
to set new field value
db.collectionName.update({}, {$set: {col2: '$col1'}}, {multi: true})