1、字段类型判断

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

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

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

 

4、mongodb更改字段类型 随笔 第1张

 

  • 数据类型批量转换(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)})

4、mongodb更改字段类型 随笔 第2张

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄