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

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐