• mongodb导出数据到csv


    mongo cws export.js > out.csv

    export.js

    // 
    Date.prototype.getIOSDate = function () {
      return new Date(this.getTime() + this.getTimezoneOffset() * 60 * 1000)
    }
    
    print('磨机A')
    printCsv('aaaaaa')
    
    
    function printCsv(device) {
      print('日期,时间,给水量,给煤量,添加剂添加量,磨机出料槽煤浆浓度,磨机出料槽煤浆温度,磨机出料槽煤浆粘度,煤浆槽煤浆瞬时流量,煤浆槽煤浆浓度,煤浆槽煤浆温度,煤浆槽煤浆粘度')
      db.coal_slurry_run.find({"deviceid":device}).forEach(data=>{
          print(`${format(data.datetime.getIOSDate())},${data.time},${data.water.nullfloat64.float64},${data.coal.nullfloat64.float64},${data.additive.nullfloat64.float64},${data.outconcentration.nullfloat64.float64},${data.outtemperature.nullfloat64.float64},${data.outviscosity.nullfloat64.float64},${data.instantflow.nullfloat64.float64},${data.highconcentration.nullfloat64.float64},${data.hightemperature.nullfloat64.float64},${data.highviscosity.nullfloat64.float64}`)
      })
    }
    
    
    function format(date) {
      return date.getFullYear() + '-' +('0' + (date.getMonth()+1)).slice(-2) + '-' + date.getDate()
    }
    
    
  • 相关阅读:
    015-面向对象
    017-错误和异常
    019-File
    020-OS
    021-模块
    022-标准库
    数据库目录
    数据库 概念详解
    MySQL 基础
    MySQL 数据库操作
  • 原文地址:https://www.cnblogs.com/warrior/p/9267238.html
Copyright © 2020-2023  润新知