Using self-referenced MongoDB values ​​in a query

Is it possible to get a self-referenced value in an update request in MongoDB? In MySQL, you can run:

UPDATE table SET column1 = column2 + column3,...

From what I know, only MapReduce can be used for this, and the server one in MongoDB. How to use MapReduce for this?

+3
source share
1 answer

Is it possible to get a self-referenced value in an update request in MongoDB?

No, this update is not possible with the regular request / update system.

From what I know, only MapReduce can be used for this, and the server one in MongoDB.

Map / Reduce is used to summarize existing data and output this data to a separate collection / table. Map / Reduce is not intended to update existing data.

MongoDB, for , . , .

db.table.find().forEach( function(x) {
  var newValue = x.column2 + x.column3; // Add column2 & 3
  db.table.update({_id: x._id}, { $set: { column1: newValue } }); // Set the value on column1
} )
+3

All Articles