0

在 MongoDB 集合中进行更新时,有什么方法可以访问文档的原始值?我一直在做以下事情:

db.things.find().forEach(function (t) {
  t.name = t.name + ' new'; // Appends ' new' to the end of the original value
  db.things.save(t);
});

上面的性能相当慢(不过,我正在处理 220 万个文档),所以我希望传统的 update() 性能更好。我检查了文档,但我没有注意到任何提到将原始值的一部分应用于 $set 值的内容。

4

1 回答 1

1

您不能在更新中使用对象中的任何内容。你用循环做的方式是最好的方式。

于 2012-05-01T20:28:55.250 回答