如何在mongodb中将数据从一列移动到另一列?

如何在mongodb中将数据从一列移动到另一列?,mongodb,Mongodb,我想把我的数据从“人口统计.教育”一栏移到“人口统计.学校”。我怎么能这样做 例如: db.users.update({"demographic.education":{$exists: true, $ne: ""}}, {$set: {"demographic.school":demographic.education}}) 您可以为此使用$rename修饰符: db.users.update({"demographic.education": {$exists: true, $ne: ""

我想把我的数据从“人口统计.教育”一栏移到“人口统计.学校”。我怎么能这样做

例如:

db.users.update({"demographic.education":{$exists: true, $ne: ""}}, {$set: {"demographic.school":demographic.education}})

您可以为此使用
$rename
修饰符:

db.users.update({"demographic.education": {$exists: true, $ne: ""}}, {$rename: {"demographic.education": "demographic.school"}})

您的意思是复制值(保持人口统计教育的原样)还是重命名密钥?重命名密钥。但是,如果我也想复制这些值,那会是什么样子呢?这并不是那么容易。基本上,您必须遍历集合并逐个修改每个文档。如果我要复制值而不是重命名,它会是什么样子?仅供将来使用。