欢迎来到學長的博客

人生三从境界:昨夜西风凋碧树,独上高楼,望尽天涯路。 衣带渐宽终不悔,为伊消得人憔悴。 众里寻他千百度,蓦然回首,那人却在灯火阑珊处。

4、mongodb更改字段类型

1、字段类型判断

db.tb_name.find({"status":{$type:"double"}).count() //所有的status字段类型为Double类型的

db.tb_name.find({"status":{$type:1}).count() //所有status字段类型为Double类型的

 

 

  • 数据类型批量转换(double转为int32):db.tb_name.find({"status":{$type:1}}).forEach(function(x){x.status=NumberInt(x.status);db.tb_name.save(x)})

 

  • (string转为array):db.log.find({"record":{$type:2}}).forEach(function(x){x.record=Array(x.record);db.log.save(x)})

posted on 2019-05-07 15:50  學長  阅读(9730)  评论(0编辑  收藏  举报

导航