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)})


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM