我蒙戈结构如下,
"topProcesses" : [
{
"cpuUtilizationPercent" : "0.0",
"processId" : "1",
"memoryUtilizationPercent" : "0.1",
"command" : "init",
"user" : "root"
},
{
"cpuUtilizationPercent" : "0.0",
"processId" : "2",
"memoryUtilizationPercent" : "0.0",
"command" : "kthreadd",
"user" : "root"
},
{
"cpuUtilizationPercent" : "0.0",
"processId" : "3",
"memoryUtilizationPercent" : "0.0",
"command" : "ksoftirqd/0",
"user" : "root"
},
{
"cpuUtilizationPercent" : "0.0",
"processId" : "5",
"memoryUtilizationPercent" : "0.0",
"command" : "kworker/0:+",
"user" : "root"
},
{
"cpuUtilizationPercent" : "0.0",
"processId" : "6",
"memoryUtilizationPercent" : "0.0",
"command" : "kworker/u3+",
"user" : "root"
},
{
"cpuUtilizationPercent" : "0.0",
"processId" : "8",
"memoryUtilizationPercent" : "0.0",
"command" : "rcu_sched",
"user" : "root"
}
]
现在,在上述文件topProcesses.cpuUtilizationPercent
是字符串,我想改变topProcesses.cpuUtilizationPercent
数据类型为Float
。 对于这个下面我试过,但没有奏效
db.collectionName.find({
"topProcesses":{"$exists":true}}).forEach(function(data){
for(var ii=0;ii<data.topProcesses.length;ii++){
db.collectionName.update({_id: data._id},{$set:{"topProcesses.$.cpuUtilizationPercent":parseFloat(data.topProcesses[ii].cpuUtilizationPercent)}},false,true);
}
})
任意一个帮助如何改变字符串可以漂浮在嵌套蒙戈文件