Redirect output of mongo query to a csv file

后端 未结 7 813
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 06:01

I am using MongoDB 2.2.2 for 32-bit Windows7 machine. I have a complex aggregation query in a .js file. I need to execute this file on the shell and direct the output to a C

7条回答
  •  遥遥无期
    2020-12-02 06:25

    Mongo's in-built export is working fine, unless you want to any data manipulation like format date, covert data types etc.

    Following command works as charm.

        mongoexport -h localhost -d databse -c collection --type=csv 
        --fields erpNum,orderId,time,status 
        -q '{"time":{"$gt":1438275600000}, "status":{"$ne" :"Cancelled"}}' 
        --out report.csv
    

提交回复
热议问题