且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MongoDB:使用$ concat更新字段值时出现问题

更新时间:2023-01-15 12:08:55

$ concat是聚合管道,而不是更新运算符/修饰符。

$concat is an aggregation pipeline, not an update operator/modifier.

似乎您可以通过以下操作来实现:

It seems that what you're trying to do can be achieved by doing the following:

db.col_1
  .find({ "field_1": { $lt: 10000 } })
  .forEach( function(i) {
    db.col_1.update(
      { _id: i._id },
      { $set: { "field_1": "0" + i.field_1 } }
    )
   });