Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一些文件:
{"required" : 100, "total" : 30}
我想更新文档,使得 required = total (无论 total 的值是什么)。我努力了:
db.collection.update({}, {"$set" : {"required" : "total"}})
但这将其设置为字符串文字“total”,在这种情况下,我如何访问该字段的值30。
30
你不能那样做。试试这个:
db.collection.find().forEach(function(d) { d.required = d.total; db.collection.save(d); });