MongoDB修改数据类型,int与字符串互转

operator_log为集合名,operation_type为字段名

{$type:2}代表type是2的,即字符串,查询所有字符串的forEach,并复制,保存

db.operator_log.find({"operation_type":{$type:2}}).forEach(function(x)
{
x.operation_type=NumberInt(x.operation_type);
db.operator_log.save(x);
}
)

db.operator_log.find({"operation_type":{$exists:true}}).forEach(function(x){
    x.operation_type=x.operation_type+"";   // 用new string(x.operation_type)就变成了文档,不知道为什么
    db.operator_log.save(x);
});

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章