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);
});
本文详细介绍了如何在MongoDB中将特定字段从字符串类型转换为整数类型,以及反向操作,通过使用find和forEach方法遍历并更新数据库中的记录。
3万+

被折叠的 条评论
为什么被折叠?



